VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,424 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,506 people online right now. Registration is fast and FREE... Join Now!




Tell me about declaring string variables.

 

Tell me about declaring string variables.

ILoveSushi

1 Jul, 2009 - 12:12 PM
Post #1

New D.I.C Head
*

Joined: 1 Jul, 2009
Posts: 13

I've just started learning VB. I can't get how to declare string variables in VB. I need some help.

User is offlineProfile CardPM
+Quote Post


PsychoCoder

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:15 PM
Post #2

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
It's rather simple

CODE

Dim SomeVariable As String


What exactly were your looking for?
User is offlineProfile CardPM
+Quote Post

ILoveSushi

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:18 PM
Post #3

New D.I.C Head
*

Joined: 1 Jul, 2009
Posts: 13

Being able to do both either a string variable or a numeric veriable.
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:20 PM
Post #4

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Declaring an integer variable is the same as a string variable

CODE

Dim SomeVariable As String

Dim AnotherVariable As Integer

User is offlineProfile CardPM
+Quote Post

ILoveSushi

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:25 PM
Post #5

New D.I.C Head
*

Joined: 1 Jul, 2009
Posts: 13

Awesome. Thank you.
User is offlineProfile CardPM
+Quote Post

ILoveSushi

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:34 PM
Post #6

New D.I.C Head
*

Joined: 1 Jul, 2009
Posts: 13

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.

CODE

'problem1.vbs'

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

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

User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:36 PM
Post #7

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

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

CODE

Dim aString As String
Dim bString as String

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

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

User is offlineProfile CardPM
+Quote Post

ILoveSushi

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:39 PM
Post #8

New D.I.C Head
*

Joined: 1 Jul, 2009
Posts: 13

Still giving me the same error.
CODE

'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: 1 Jul, 2009 - 12:45 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:44 PM
Post #9

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

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

CODE

Dim aString, bString

aString = "Hellp"
bString = "World"

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

User is offlineProfile CardPM
+Quote Post

ILoveSushi

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:46 PM
Post #10

New D.I.C Head
*

Joined: 1 Jul, 2009
Posts: 13

QUOTE(PsychoCoder @ 1 Jul, 2009 - 12:44 PM) *

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

CODE

Dim aString, bString

aString = "Hellp"
bString = "World"

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



Awesome. Now it works.
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 12:57 PM
Post #11

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Glad I could help smile.gif

Now go forth and become a Variable Declaring Guru smile.gif
User is offlineProfile CardPM
+Quote Post

ILoveSushi

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 01:06 PM
Post #12

New D.I.C Head
*

Joined: 1 Jul, 2009
Posts: 13

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

CODE

Dim aString, bString, cString

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

User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Tell Me About Declaring String Variables.

1 Jul, 2009 - 01:07 PM
Post #13

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

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

CODE

cString = aString & bString


Also, when mentioning that you're getting errors let us know what the error message if that you're receiving smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:19AM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month