English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Following code i use :

Public Class Form1
Dim myisTime As Boolean

Public Property isTime() As Boolean
Get
Return myisTime
End Get
Set(ByVal value As Boolean)
myisTime = value
End Set
End Property


Public Shared Sub TestProp()

If isTime Then
msgbox("Yes..timings are on....")
else
msgbox("No....timings are off...")
end if
End Sub

Private Sub CheckBoxisTime_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxLocalTime.CheckedChanged
isTime = CheckBoxisTime.Checked
End Sub
End Class

isTime gives error of instantiation...can't use it without instance of class.....

How to deal with ? where i am wrong please help.

2006-10-21 21:25:13 · 2 answers · asked by VBNewComer 1 in Computers & Internet Programming & Design

That means, move whole declaration portion of isTime code to another module, then initialise it, save that variable in that module and use it from that module is it ?

2006-10-21 21:57:40 · update #1

That way is ok, but is there any otherway like if i make whole project one NameSpace and then do it ? I use only one form application and want to check that isTime checkbox is checked, do one thing otherwise, other. And while my one form application is running, variable declared in same class should be accessable, isn't it ?

Thanks for helping me out....

2006-10-22 01:18:32 · update #2

2 answers

Your form has to be loaded and running for this to work. That's why it has to be in another module unless you change your app design such that this form never unloads.

I wouldn't use a module though - that's a VB only design technique. A more appropriate way to do it would be in a class as a static shared variable.

public Class TimerWatcher


'doesn't need to be a property
Public shared IsTime as boolean

Public Shared Sub TestProp()
If isTime Then
msgbox("Yes..timings are on....")
else
msgbox("No....timings are off...")
end if
End Sub

End Class

2006-10-21 23:44:39 · answer #1 · answered by evolver 6 · 0 0

Move entire you "isTime" code into a new module, let's call it Module1
In your CheckBoxisTime_CheckedChanged sub, initialize your object by the following statement
Set time1 = new Module1
Module1.isTime = ...

2006-10-21 21:35:54 · answer #2 · answered by trung thanh 2 · 0 0

fedest.com, questions and answers