Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Problem to the codes

Posted on 2015-01-26
Medium Priority
Last Modified: 2015-01-26
Here are the codes

Dim val1 As Integer val1=InputBox("Enter a Number","Enter Value") Msgbox val1

Open in new window

and I don't know why I get the attached error.
Question by:HuaMinChen
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Author Comment

ID: 40570248
Due to some reason, I need to combine the lines of codes into one line, as shown in above.
LVL 18

Expert Comment

ID: 40570274
See MSDN VBScript Variables
In VBScript, variables are always of one fundamental data type, Variant.

If I remove the data type from your DIM statement and split it into separate lines, the code runs fine (in VBScript).
Dim val1 'As Integer 
val1=InputBox("Enter a Number","Enter Value") 
Msgbox val1

Open in new window

What is the reason you need the code on one line?
LVL 46

Expert Comment

ID: 40570524
You have coded a VB.Net form of the statement.  Are you developing in VB.Net or VB6/VBA?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 86

Expert Comment

by:Mike Tomlinson
ID: 40570600
In addition to SimonAdept's correct solution on removing the type, if you want it all on one line then simply separate each line by a colon like this:
Dim val1 : val1=InputBox("Enter a Number","Enter Value") : Msgbox val1

Open in new window

LVL 11

Author Comment

ID: 40571822
Thanks all.

Sorry, I have put this

Dim val1 As Integer : val1=InputBox("Enter a Number","Enter Value") : Msgbox val1

Open in new window

but I still get the attached error

I need to put all into one line.
LVL 86

Accepted Solution

Mike Tomlinson earned 1500 total points
ID: 40571934
As stated before (twice), remove the type of the variable.


    Dim val1 As Integer :


    Dim val1  :

Look closely at my example...

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question