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

Username:   Password: 
 RegisterRegister   
 Opening a Form With Arguments
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
GlobeTrotter




PostPosted: Tue Nov 29, 2005 8:39 pm   Post subject: Opening a Form With Arguments

Basically, my first form is a settings form where information about the number, and type of players is entered. The next form is the game form. I store player info in a flexible array of a public type. How can I pass this array of players from the settings form to the game form. I'd like to avoid using Global variables, if possible, as they are 'apparently' bas coding practice.

I tried this type of thing:

Settings Form:
code:
Option Explicit

Dim Player() As GamePlayer

Public Sub StartGame
    Call frmGame.InitGame(Player)
    Me.Show
End Sub


Game Form:
note- the code inside the procedure is kind of pseudo-code.
code:

Option Explicit

Dim Player() As GamePlayer

Public Sub InitGame(TempPlayers() As GamePlayer)
    Player = TempPlayers
    Me.Show
End Sub



I get the following error:

Compile Error:

Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types


I don't really understand it. I declared my GamePlayer record as a public type in a seperate module.

If I am going about this all wrong, please let me know also.
Sponsor
Sponsor
Sponsor
sponsor
pavol




PostPosted: Wed Nov 30, 2005 8:22 am   Post subject: (No subject)

if you already declared your GamePlayer record in the module why don't you make it easier on yourself and just declare your array there instead of trying to declare a public record and sending a private variable to it.

I think this error is just telling you that you can't use a public types or procedures and give them a 'non-public' parameter.
Brightguy




PostPosted: Sat Dec 03, 2005 4:05 pm   Post subject: Re: Opening a Form With Arguments

The rule is... public procedures cannot return or have user-defined types for parameters. (Even if the user-defined type is public.)

You could do it by individually passing all the variables in your udt, but it'll be easier to just use a public variable.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: