12 Replies - 791 Views - Last Post: 01 July 2009 - 02:07 PM Rate Topic: -----

#1 ILoveSushi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-July 09

Tell me about declaring string variables.

Post icon  Posted 01 July 2009 - 01:12 PM

I've just started learning VB. I can't get how to declare string variables in VB. I need some help.
Is This A Good Question/Topic? 0
  • +

Replies To: Tell me about declaring string variables.

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:15 PM

It's rather simple

Dim SomeVariable As String



What exactly were your looking for?
Was This Post Helpful? 0
  • +
  • -

#3 ILoveSushi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-July 09

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:18 PM

Being able to do both either a string variable or a numeric veriable.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:20 PM

Declaring an integer variable is the same as a string variable

Dim SomeVariable As String

Dim AnotherVariable As Integer


Was This Post Helpful? 0
  • +
  • -

#5 ILoveSushi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-July 09

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:25 PM

Awesome. Thank you.
Was This Post Helpful? 0
  • +
  • -

#6 ILoveSushi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-July 09

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:34 PM

Everytime I try to run this, it gives me an error on line 3, char 13 with an error message: Expected end of statement. I'm using Notepad.

'problem1.vbs'

Dim aString As String = "Hello"
Dim bString as String = "World"

' Displays "HelloWorld." '
MsgBox(aString & bString)


Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:36 PM

Declaring a variable and setting it are two different tasks. Try this

Dim aString As String
Dim bString as String

Set aString = "Hellp"
Set bString = "World"

' Displays "HelloWorld." '
MsgBox(aString & bString)


Was This Post Helpful? 0
  • +
  • -

#8 ILoveSushi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-July 09

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:39 PM

Still giving me the same error.
'problem1.vbs'

Dim aString As String
Dim bString As String

Set aString = "Hello"
Set bString = "World"

' Displays "HelloWorld." '
MsgBox(aString & bString)



Says the problem is on line 3, character 13 with an expected end of statement.

This post has been edited by ILoveSushi: 01 July 2009 - 01:45 PM

Was This Post Helpful? 0
  • +
  • -

#9 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:44 PM

My bad, by default all VBScript variables are of type Variant, and can hold any kind of data type. Try this:

Dim aString, bString

aString = "Hellp"
bString = "World"

' Displays "HelloWorld." '
MsgBox(aString & bString)


Was This Post Helpful? 0
  • +
  • -

#10 ILoveSushi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-July 09

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:46 PM

View PostPsychoCoder, on 1 Jul, 2009 - 12:44 PM, said:

My bad, by default all VBScript variables are of type Variant, and can hold any kind of data type. Try this:

Dim aString, bString

aString = "Hellp"
bString = "World"

' Displays "HelloWorld." '
MsgBox(aString & bString)



Awesome. Now it works.
Was This Post Helpful? 0
  • +
  • -

#11 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 01:57 PM

Glad I could help :)

Now go forth and become a Variable Declaring Guru :)
Was This Post Helpful? 0
  • +
  • -

#12 ILoveSushi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-July 09

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 02:06 PM

I'm also attempting to append a string to another string. Here's my code. It keeps giving me errors.

Dim aString, bString, cString

aString = "Hellp"
bString = "World"
cString = aString//bString
' Displays "HelloWorld." '
MsgBox(cString)


Was This Post Helpful? 0
  • +
  • -

#13 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Tell me about declaring string variables.

Posted 01 July 2009 - 02:07 PM

Not sure why you have a // in between the two variables but do this

cString = aString & bString



Also, when mentioning that you're getting errors let us know what the error message if that you're receiving :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1