![]() |
excel vb question
Greetings,
I am writing some vb code in excel (version that comes with Office 2000). I am a programmer, and really haven't dealt with excel before. If I define a public variable on the workbook, can I initialize it at definition ? ie, public test as integer init 0 How do I initialize the variable (or determine it needs initialization) before using it ? thanks, -D |
excel vb question
Darryl,
You can use a constant Public Const test As Integer = 0 of course, that stops you changing it later. -- HTH RP (remove nothere from the email address if mailing direct) "Darryl" wrote in message ... Greetings, I am writing some vb code in excel (version that comes with Office 2000). I am a programmer, and really haven't dealt with excel before. If I define a public variable on the workbook, can I initialize it at definition ? ie, public test as integer init 0 How do I initialize the variable (or determine it needs initialization) before using it ? thanks, -D |
excel vb question
Sorry I wasn't very clear.
I need it to be a variable as I'm going to increment it as I do certain things. "Bob Phillips" wrote in message ... Darryl, You can use a constant Public Const test As Integer = 0 of course, that stops you changing it later. -- HTH RP (remove nothere from the email address if mailing direct) "Darryl" wrote in message ... Greetings, I am writing some vb code in excel (version that comes with Office 2000). I am a programmer, and really haven't dealt with excel before. If I define a public variable on the workbook, can I initialize it at definition ? ie, public test as integer init 0 How do I initialize the variable (or determine it needs initialization) before using it ? thanks, -D |
excel vb question
Then you can't initialise is as you thought. What you can do is something
like this Public test As Variant Sub myCode() If IsEmpty(test) Then test = 0 End If 'rest of code End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Darryl" wrote in message ... Sorry I wasn't very clear. I need it to be a variable as I'm going to increment it as I do certain things. "Bob Phillips" wrote in message ... Darryl, You can use a constant Public Const test As Integer = 0 of course, that stops you changing it later. -- HTH RP (remove nothere from the email address if mailing direct) "Darryl" wrote in message ... Greetings, I am writing some vb code in excel (version that comes with Office 2000). I am a programmer, and really haven't dealt with excel before. If I define a public variable on the workbook, can I initialize it at definition ? ie, public test as integer init 0 How do I initialize the variable (or determine it needs initialization) before using it ? thanks, -D |
excel vb question
OK.
If I define a variable that is integer, is it automatically initialized to 0 or can it be any old garbage ? I'm going to keep adding 1 to the variable each time a button is pressed and I don't want to do something like test = test +1 if test is garbage. thanks, D I assume that IsEmpty only works with variant type variables ? "Bob Phillips" wrote in message ... Then you can't initialise is as you thought. What you can do is something like this Public test As Variant Sub myCode() If IsEmpty(test) Then test = 0 End If 'rest of code End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Darryl" wrote in message ... Sorry I wasn't very clear. I need it to be a variable as I'm going to increment it as I do certain things. "Bob Phillips" wrote in message ... Darryl, You can use a constant Public Const test As Integer = 0 of course, that stops you changing it later. -- HTH RP (remove nothere from the email address if mailing direct) "Darryl" wrote in message ... Greetings, I am writing some vb code in excel (version that comes with Office 2000). I am a programmer, and really haven't dealt with excel before. If I define a public variable on the workbook, can I initialize it at definition ? ie, public test as integer init 0 How do I initialize the variable (or determine it needs initialization) before using it ? thanks, -D |
excel vb question
Yes, an integer initialises to 0 every time.
-- HTH RP (remove nothere from the email address if mailing direct) "Darryl" wrote in message ... OK. If I define a variable that is integer, is it automatically initialized to 0 or can it be any old garbage ? I'm going to keep adding 1 to the variable each time a button is pressed and I don't want to do something like test = test +1 if test is garbage. thanks, D I assume that IsEmpty only works with variant type variables ? "Bob Phillips" wrote in message ... Then you can't initialise is as you thought. What you can do is something like this Public test As Variant Sub myCode() If IsEmpty(test) Then test = 0 End If 'rest of code End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Darryl" wrote in message ... Sorry I wasn't very clear. I need it to be a variable as I'm going to increment it as I do certain things. "Bob Phillips" wrote in message ... Darryl, You can use a constant Public Const test As Integer = 0 of course, that stops you changing it later. -- HTH RP (remove nothere from the email address if mailing direct) "Darryl" wrote in message ... Greetings, I am writing some vb code in excel (version that comes with Office 2000). I am a programmer, and really haven't dealt with excel before. If I define a public variable on the workbook, can I initialize it at definition ? ie, public test as integer init 0 How do I initialize the variable (or determine it needs initialization) before using it ? thanks, -D |
All times are GMT +1. The time now is 08:05 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com