Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default 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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
String or integer? JustinP Excel Programming 2 September 5th 06 06:56 AM
adding an integer to a string in code pspyve[_8_] Excel Programming 2 August 15th 06 12:45 AM
Compare string with integer hurriance[_8_] Excel Programming 2 June 26th 06 09:14 AM
Concatenating a string and an integer [email protected] Excel Programming 2 April 5th 06 07:40 PM
Concatenate two variables (String & Integer) Sreenivas Varadhan Excel Programming 3 December 12th 05 01:28 PM


All times are GMT +1. The time now is 05:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"