Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 I don't know why this isn't working
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
awesomej01




PostPosted: Fri Apr 30, 2004 6:36 pm   Post subject: I don't know why this isn't working

For my final project, I planed to make a word processor. As you all know, in a word processor you don't need to press a button to start typing.....you just type. That is why, I made a procedure, that "getch" the input and quit the procedure when the user goes on to click a button that would take them to a different option or tool. My code looks like this, however it doesn't work because it just keep getching and it won't exit the loop when the user clicks on another button.

This is basically what the code looks like

procedure text
var x, y, btn : int
loop
mousewhere (x, y, btn)
getch (ch) %character input
exit when x >= 11 and x <= 90 and y >= 435 and y <= 460 and btn = 1
%This exit condition is if the user clicks on a specific button
%But it doesn't exit, all it does is it keep getching

................

ch:=message+ch
Font.Draw (message, 271, line, font1, 7)
end loop
end text
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Fri Apr 30, 2004 6:50 pm   Post subject: (No subject)

may be u should do:

code:

if hasch then
getch(ch)
end if


insted of just

code:

getch(ch)


this way it will only get a ch if there is one to get...
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
awesomej01




PostPosted: Fri Apr 30, 2004 7:04 pm   Post subject: (No subject)

The problem with that is that I am not just getching one character and that is it. Because i am making a word processor, I am getching a whole bucnch of character so I put it into a loop then add that character to a string variable called message like

this...

getch (ch)
message := ch+message
Font.Draw (message, x,y, font,color)

The only problem is that there is something wrong with my exit when condition. My exit when statement says if the button is pressed on a certain button then exit this procedure. However it doesn't work, the subprogram just keep getching forever.

I hope I clarified my problem better this one so if there is anyone that is not busy and don't mind to help me, can they post a solution for my problem. Thanks!
Dan




PostPosted: Fri Apr 30, 2004 7:19 pm   Post subject: (No subject)

could you post your hole code? that may make it easer for me to see what is going on.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
awesomej01




PostPosted: Fri Apr 30, 2004 7:31 pm   Post subject: (No subject)

sure no problem. This is the sub program and the main program is at the bottom.

drawbox (11,460,90,435,7)

var Courier:=Font.New("Courier:10")
Font.Draw ("Open: ",30,445,Courier,7)

var ch :string(1)
var message : string :=" "
procedure text
var x, y, btn : int
loop
mousewhere (x, y, btn)
getch (ch)
exit when x >= 11 and x <= 90 and y >= 435 and y <= 460 and btn = 1
%This line doesn't work
message := message + ch
View.ClipSet (271, 101, 737, 480) %textbox
Font.Draw (message, 271, line, font1, 7)
if ch = " " then
counter := counter + 0
else
counter := counter + 1
end if
if counter > 51 then
count := 0
line := line - 18
message := " "
counter := 0
end if
end loop
end text

%This is the Main Program

var x, y, btn : int
loop
mousewhere (x,y, btn)
if x >= 11 and x <= 90 and y >= 435 and y <= 460 and btn = 1 then
put "Open"
else
text
end if
end loop
Dan




PostPosted: Fri Apr 30, 2004 8:51 pm   Post subject: (No subject)

wow, there is alot wrong there:

i dont think u are full understaning how the mouse comands work. when u check where the mouse is using mousewhere, it gives the int value of the x and y value at the excat monment in time when u call that, but what u are doing is asuming it will keep checking the mouses loaction on buttion intill what happens in your if stament happans. but thats not how it works.

like in the main progame, it will check where the mouse is for less then a millasceond then go to the test subprogame.

in the test subprogame for it to exit you whould have to hit a key and then click open b4 turing could check the values returnd from the mousewhere comand with is not psicaly posable.

you need to put in if hasch then like i side so it is not allways wating for input. then your exit stament will work. but there is a simmialer problem in your main progame. the best idea whould be not to loop the subprogame and put the if hasch in the subproame.

also i do not think that u are using View.ClipSet right or at least it is not working right on my comp.

so somting like this:

code:


procedure text

    if hasch then
        getch (ch)
        message := message + ch
        if ch = " " then
            counter := counter + 0
        else
            counter := counter + 1
        end if
        if counter > 51 then
            count := 0
            line := line - 18
            message := " "
            counter := 0
        end if
    end if
   
    Font.Draw (message,maxx div 2, maxy div 2, font1, 7)

end text

%This is the Main Program

var x, y, btn : int

loop
    mousewhere (x, y, btn)
    if x >= 11 and x <= 90 and y >= 435 and y <= 460 and btn = 1 then
        put "Open"
    else
        text
    end if

end loop
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
awesomej01




PostPosted: Sat May 01, 2004 7:30 am   Post subject: (No subject)

Thanks, for the fix, now I understand why it didn't work before. So the way the subprogram text works now is that it checks if the user has hit the keyboard and if it has then the program would carry on doing the text stuff and if it didn't hit the keyboard then the subprogram wouldn't execute at all.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: