ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Varaibles as both integer and String (https://www.excelbanter.com/excel-programming/382309-varaibles-both-integer-string.html)

RominallL

Varaibles as both integer and String
 
Okay, all my VB is self taught so this might seem like a really stupid
question. I do a lot of variable declarations to use in my code and I need
to use those variables as cell references and also be able to use it as an
integer. Is there some expression that I can use to say use the string of
variable X?

I saw a reference somewhere about using something like what I want but it
was for OLAP stuff. I primarily use VB in excel/access.

Currently what I do is:
Dim X as integer
Dim XStr as string
x = 0
XStr = X

Seems really redundant.

Tom Ogilvy

Varaibles as both integer and String
 
set rng = Range("B9")
msgbox rng.Text


x = 1
msgbox Format(x,"#")

Hard to tell what you mean by a cell reference and an integer or use the
string of variable X. The above are some guesses.

--
Regards,
Tom Ogilvy


"RominallL" wrote:

Okay, all my VB is self taught so this might seem like a really stupid
question. I do a lot of variable declarations to use in my code and I need
to use those variables as cell references and also be able to use it as an
integer. Is there some expression that I can use to say use the string of
variable X?

I saw a reference somewhere about using something like what I want but it
was for OLAP stuff. I primarily use VB in excel/access.

Currently what I do is:
Dim X as integer
Dim XStr as string
x = 0
XStr = X

Seems really redundant.


RominallL

Varaibles as both integer and String
 
I use it more like
X = InputBox("Please enter number")
If x <0 then ....
If x = 0 then .....
range(C"+XStr+").value = 50 (this is part of the calculations from the
'then' statements

Or maybe I'm just looking at the whole thing wrong.

"Tom Ogilvy" wrote:

set rng = Range("B9")
msgbox rng.Text


x = 1
msgbox Format(x,"#")

Hard to tell what you mean by a cell reference and an integer or use the
string of variable X. The above are some guesses.

--
Regards,
Tom Ogilvy


"RominallL" wrote:

Okay, all my VB is self taught so this might seem like a really stupid
question. I do a lot of variable declarations to use in my code and I need
to use those variables as cell references and also be able to use it as an
integer. Is there some expression that I can use to say use the string of
variable X?

I saw a reference somewhere about using something like what I want but it
was for OLAP stuff. I primarily use VB in excel/access.

Currently what I do is:
Dim X as integer
Dim XStr as string
x = 0
XStr = X

Seems really redundant.


Tom Ogilvy

Varaibles as both integer and String
 
Dim x as Integer
X = InputBox("Please enter number")
If x <0 then ....
If x = 0 then .....
range(C" & cstr(x) ).value = 50


or you can let VBA implicitly do the conversion
range(C" & x ).value = 50

by the way, the value returned from inputbox is a string. If you dim x as
integer, then excel implicitly converts it to integer.

--
Regards,
Tom Ogilvy

"RominallL" wrote:

I use it more like
X = InputBox("Please enter number")
If x <0 then ....
If x = 0 then .....
range(C"+XStr+").value = 50 (this is part of the calculations from the
'then' statements

Or maybe I'm just looking at the whole thing wrong.

"Tom Ogilvy" wrote:

set rng = Range("B9")
msgbox rng.Text


x = 1
msgbox Format(x,"#")

Hard to tell what you mean by a cell reference and an integer or use the
string of variable X. The above are some guesses.

--
Regards,
Tom Ogilvy


"RominallL" wrote:

Okay, all my VB is self taught so this might seem like a really stupid
question. I do a lot of variable declarations to use in my code and I need
to use those variables as cell references and also be able to use it as an
integer. Is there some expression that I can use to say use the string of
variable X?

I saw a reference somewhere about using something like what I want but it
was for OLAP stuff. I primarily use VB in excel/access.

Currently what I do is:
Dim X as integer
Dim XStr as string
x = 0
XStr = X

Seems really redundant.


RominallL

Varaibles as both integer and String
 
Hey I didn't know about using the & or cstr function.

Yeah, I know about the input box thing, I actually use application.inputbox
and use number type.


One more stupid question. I've never done any error stuff, but am finding
that I need to.

I want to set up an error for when a user form (actually any user form in
the workbook) is closed using the little X in the corner (error 9, I believe)
but when I add it to the user form it doesn't seem to see it. Do I need to
add it to a module level or something?

I'm one of those people who probably make you shudder. I know enough that
some things can be done but not enough to do them correctly.
"Tom Ogilvy" wrote:

Dim x as Integer
X = InputBox("Please enter number")
If x <0 then ....
If x = 0 then .....
range(C" & cstr(x) ).value = 50


or you can let VBA implicitly do the conversion
range(C" & x ).value = 50

by the way, the value returned from inputbox is a string. If you dim x as
integer, then excel implicitly converts it to integer.

--
Regards,
Tom Ogilvy

"RominallL" wrote:

I use it more like
X = InputBox("Please enter number")
If x <0 then ....
If x = 0 then .....
range(C"+XStr+").value = 50 (this is part of the calculations from the
'then' statements

Or maybe I'm just looking at the whole thing wrong.

"Tom Ogilvy" wrote:

set rng = Range("B9")
msgbox rng.Text


x = 1
msgbox Format(x,"#")

Hard to tell what you mean by a cell reference and an integer or use the
string of variable X. The above are some guesses.

--
Regards,
Tom Ogilvy


"RominallL" wrote:

Okay, all my VB is self taught so this might seem like a really stupid
question. I do a lot of variable declarations to use in my code and I need
to use those variables as cell references and also be able to use it as an
integer. Is there some expression that I can use to say use the string of
variable X?

I saw a reference somewhere about using something like what I want but it
was for OLAP stuff. I primarily use VB in excel/access.

Currently what I do is:
Dim X as integer
Dim XStr as string
x = 0
XStr = X

Seems really redundant.


Tom Ogilvy

Varaibles as both integer and String
 
I don't know about raising an error, but you can prevent it with the
queryclose event:

http://support.microsoft.com/kb/213713/en-us
XL2000: Preventing UserForm from Being Dismissed with Close Button

--
Regards,
Tom Ogilvy


"RominallL" wrote:

Hey I didn't know about using the & or cstr function.

Yeah, I know about the input box thing, I actually use application.inputbox
and use number type.


One more stupid question. I've never done any error stuff, but am finding
that I need to.

I want to set up an error for when a user form (actually any user form in
the workbook) is closed using the little X in the corner (error 9, I believe)
but when I add it to the user form it doesn't seem to see it. Do I need to
add it to a module level or something?

I'm one of those people who probably make you shudder. I know enough that
some things can be done but not enough to do them correctly.
"Tom Ogilvy" wrote:

Dim x as Integer
X = InputBox("Please enter number")
If x <0 then ....
If x = 0 then .....
range(C" & cstr(x) ).value = 50


or you can let VBA implicitly do the conversion
range(C" & x ).value = 50

by the way, the value returned from inputbox is a string. If you dim x as
integer, then excel implicitly converts it to integer.

--
Regards,
Tom Ogilvy

"RominallL" wrote:

I use it more like
X = InputBox("Please enter number")
If x <0 then ....
If x = 0 then .....
range(C"+XStr+").value = 50 (this is part of the calculations from the
'then' statements

Or maybe I'm just looking at the whole thing wrong.

"Tom Ogilvy" wrote:

set rng = Range("B9")
msgbox rng.Text


x = 1
msgbox Format(x,"#")

Hard to tell what you mean by a cell reference and an integer or use the
string of variable X. The above are some guesses.

--
Regards,
Tom Ogilvy


"RominallL" wrote:

Okay, all my VB is self taught so this might seem like a really stupid
question. I do a lot of variable declarations to use in my code and I need
to use those variables as cell references and also be able to use it as an
integer. Is there some expression that I can use to say use the string of
variable X?

I saw a reference somewhere about using something like what I want but it
was for OLAP stuff. I primarily use VB in excel/access.

Currently what I do is:
Dim X as integer
Dim XStr as string
x = 0
XStr = X

Seems really redundant.



All times are GMT +1. The time now is 02:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com