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

Username:   Password: 
 RegisterRegister   
 sending info from one form to the other
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cool dude




PostPosted: Mon Dec 26, 2005 11:09 am   Post subject: sending info from one form to the other

hi how do u send information from one form to the other form? for instance if i chose one of the options in the combo box how would i know which option i chose in the other form?
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Mon Dec 26, 2005 1:05 pm   Post subject: (No subject)

***Edit***
does anybody know wats wrong with this code. i made a combo box with the choices easy, medium, hard, and insane. i want to figure out which one was chosen and then i want to send it to my main program where the chosen speed will occur.

code:

Option Explicit

Dim speed(3) As Integer

Private Sub cboDifficulty_Change()
    If cboDifficulty.Listindex = 0 Then
       cboDifficulty.Listindex = speed(0)
    ElseIf cboDifficulty.Listindex = (1) Then
        cboDifficulty.Listindex = speed(1)
    ElseIf cboDifficulty.Listindex = (2) Then
        cboDifficulty.Listindex = speed(2)
    ElseIf cboDifficulty.Listindex = (3) Then
        cboDifficulty.Listindex = speed(3)
    End If
End Sub


The error that i get is subscript out of range in the main program
HazySmoke)345




PostPosted: Mon Dec 26, 2005 2:51 pm   Post subject: (No subject)

Well, When I ran the program, the program didn't run through the script at all. I don't really know why that happens. But I think I know what's wrong. First, maybe you shouldn't have created an array for speed. Speed can be either 0,1,2 or 3, so I would change it to something like this:
code:
Dim speed As Integer


Secondly:
code:
ElseIf cboDifficulty.Listindex = (1) Then
Are you really supposed to put brackets around the 1? Laughing

Thirdly:
code:
cboDifficulty.Listindex = speed(0)
Shouldn't it be the other way around, as in,
code:
speed = cboDifficulty.Listindex
HazySmoke)345




PostPosted: Mon Dec 26, 2005 2:57 pm   Post subject: (No subject)

Oh, and, if you want to send information inter-Form-ly. This is what you do. Let's say that you created Text1, cmd in Form1 and Text2 in Form2. And you want to send whatever is written in Text1 to Text2 by the click of the button. This is what you write

code:
Private Sub cmd_Click()
    Form2.Text2 = Form1.Text1
End Sub
cool dude




PostPosted: Mon Dec 26, 2005 3:32 pm   Post subject: (No subject)

HazySmoke)345 wrote:


Secondly:
code:
ElseIf cboDifficulty.Listindex = (1) Then
Are you really supposed to put brackets around the 1? Laughing



No u don't have to place the brackets on the 1 i didn't even notice that i did that. Embarassed but that does nothing anyways so thats not the problem.

Quote:

Thirdly:
code:
cboDifficulty.Listindex = speed(0)
Shouldn't it be the other way around, as in,
code:
speed = cboDifficulty.Listindex




yes it should be around srry for that stupid mistake

Now back to the main problem. watever speed the user chooses in the combo box that speed must effect the main program. which means if they chose easy than my main program should know that and adjust the timer intervals smaller or greater to make it go faster or slower. now i don't know how to pass the variable speed that they choose in the combo box to my main program. the example u gave me

code:

Private Sub cmd_Click()
    Form2.Text2 = Form1.Text1
End Sub


this is only good if u want the information from one textbox to the other i dunno how to do the same thing with the speed. can u please explain how i would go about doing this?
cool dude




PostPosted: Mon Dec 26, 2005 4:34 pm   Post subject: (No subject)

okay i fixed it all up and all i need to know is when the user clicks on the command button "play" how can i send the speed from the settings form to the main game. at the moment, because i'm not sending the speed the user chose, it sets the speeds value to 0. (default).
HazySmoke)345




PostPosted: Mon Dec 26, 2005 4:35 pm   Post subject: (No subject)

If you want to use a same variable in two forms. You can create a module and write this in it:
code:
Public speed As Integer
So that "speed" can be used in the whole project.
cool dude




PostPosted: Mon Dec 26, 2005 5:12 pm   Post subject: (No subject)

oh my god i completely forgot to declare speed as a module. thanks a lot!!! finally i got it working. Smile + 5 bits
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: