I am trying to code a varible on one of my forms as public so i can access it on other forms. Though when I try to access it another form, it says it is not declared. Am I missing something

Public Class NovaWarsLogin

Public user As String

(Other Code Here)

End Class

Re: Visual Basic Language Public variables.


Can you post the code that is giving the error when trying to access NovaWarsLogin.user

Something like this should work, though:

Re: Visual Basic Language Public variables.


I tried that and I got the same error, user is not declared. But I came up with my own code for it. I removed

Dim zz As New NovaWarsLogin
zz.user = ""

and I inserted

Dim var As String = NovaWarsLogin.user

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Label1.Text = var

End Sub

Re: Visual Basic Language Public variables.


Hi adoroxin

Adding a Class Module to your project is a sure fire way to establish public variables in your project.

From your IDE menu choose Project >>> Add Module >>> then choose Module >>> then give it a name (example: Module1)

Declare all your public variables within that class module

Here is an example of all the Public variables in one my projects (not to show off, but just a quick cut and paste for examples sake)

Module Module1

Public hbs(0 To 300) As Short

Public sgv(0 To 80) As Single

Public byt(0 To 318) As SByte

Public srj(0 To 30) As String

Public hju(0 To 236, 0 To 4, 0 To 2) As Byte

Public jip(0 To 5) As Font

Public kgn(0 To 50) As Color

Public ykm(0 To 20) As Graphics

Public yxb(0 To 20) As Bitmap

Public qko(0 To 100) As Rectangle

Public ear(0 To 100) As Point

Public lgc(0 To 4) As SizeF

Public zdu(0 To 10) As Size

Public iqv(0 To 20) As Brush

Public psj(0 To 10) As Pen

Public rfj() As FontFamily

Public rlt As New System.Drawing.Text.InstalledFontCollection()

Public I%

Public L&

Public J%

Public S!

Public K$

Public G%

Then all your variables are ready and waiting to be used in any of your forms at any time.

I find the ReadAllBytes and the WriteAllBytes methods are great for loading up your arrays or saving the data from your arrays to files.

Although I find VB2005 to be VERY SLOW at lengthy operations with a lot of nested loops, I find the ReadAllBytes and the WriteAllBytes methods to be delightfully FAST.

Thanks for hearing me