Results 1 to 13 of 13

Thread: Dim as long

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8

    Question Dim as long

    I am currenty working on a project, what I was is to dim these three txt boxes as long so the "" quotes will stop appearing and interfearing with the cmd file.
    Any help out there??

    I keeping getting a : "Type Mismatch" error - It highlights the Dim trace and the dim pause. Help!




    Private Sub cmdScan_Click()
    If Not IsNumeric(txtipadress) Then
    MsgBox "Please enter a numeric value only!", vbInformation + vbOKOnly, "Incorrect Information"
    txtipadress.SetFocus
    End If

    Dim telnum As Long
    telnum = txtipadress



    Dim trace As Long
    trace = txttrace



    Dim pause As Long
    pause = txtPause


    filename = "C:\ip.cmd"
    Open filename For Output As #1
    Write #1, telnum, trace, pause

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    The dafault properity of txtipadress.text and that is a string!
    If you want to have an IP.address (i.e. "255.255.255.0") you need to change that string into those four numbers(or does a VAR-type IP-address exist?).
    The same is probable true for "trace"
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8

    Question Why a string?

    This code works properly -

    Dim telnum As Long
    telnum = txtipadress


    The other two doesn't work. Why is it a string when I dim it as long - I even dim filename as long. Any help?

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Try using Val() or CLng().
    Tengo mas preguntas que contestas

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You could just add code to the _KeyPress event and trap for undesireable
    characters before they get in.

    VB Code:
    1. Private Sub txtIPAddress_KeyPress(KeyAscii As Integer)
    2.    
    3.     Select Case KeyAscii
    4.         Case 46, 48 To 57, 8 'Numbers, decimal, and backspace only
    5.         Case Else
    6.             Beep
    7.             KeyAscii = 0 'Cancels the keypressed character
    8.     End Select
    9.  
    10. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8

    Exclamation Still lost....

    Maybe I didn't explain what was incorrectly as well as I should have - I am trying to get rid of the quotes, when it writes it to a note pad it gives me "Ping"Whatever the IPaddress""@pause". The Ping Quotes are gone, by using the dim telnum as long; and the others - dim trace as long and dim pause as long gives me the error. I changed them to string but again it caused the quotes to come back.

    Hey thanks for the other idea taking care of undesirable charactors - helped.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Oh now I see said the blind man!

    Its how you are writting out to your file. The Write statement will
    place double quotes around each entry. Use the Print statement
    instead. It will not do that.

    Snippet:

    VB Code:
    1. filename = "C:\ip.cmd"
    2. Open filename For Output As #1
    3. Print #1, telnum, trace, pause
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8

    Lightbulb Got some of it.....

    I got the quotes to work, now I was wondering how could I get the @pause command to go below the rest of the code in a txt file? Any ideas?
    I.E.


    Text goes here
    @pause

    Thanks for the help all.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Just change the order on the Print line of code. First position is
    the last line in the text file.

    VB Code:
    1. filename = "C:\ip.cmd"
    2. Open filename For Output As #1
    3. Print #1, pause, telnum, trace
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8

    Question Last Line...

    Not needed after the rest of the words, I need it below - And BTW - The print doesn't work, just gives me: "","","" No matter what I type.

  11. #11
    Hyperactive Member Granty's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    439
    You can either put it as a separate Print statement

    Print #1, Pause
    Print #1, Telnum


    etc

    Or Print #1, Pause & vbCrLf & Telnum......

  12. #12

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8

    ???

    Is what I am trying to do impossable? Or is there another way to attack this thing?

  13. #13

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    8

    Guess not

    Okay, I figured out my last problem by myself, but a new one has risen from it's death.
    And the crazy thing is it worked for me one time and when I typed the code back in perfectly as before, it gave me some kinda error, please help!!!!!

    All I want to do at the moment is open a program and have it run through VB -
    The following code has been used and given a error message of - "Invalid Call or argument"

    Dim a
    '1 stands for open that exe
    a = Shell("H:\windows\system32\command.cmd", 1)
    End


    That doesn't work - and here is the other-----

    Open ("H:\windows\system32\command.cmd") For Append As 1

    This code too doesn't work and gives me an error message

    The command.cmd does exist as I made it before I wrote the code.
    Finally, I tried creating it -
    open ("H:\windows\system32\command.cmd") for output as 1
    and then open it

    dim a
    a = shell("H:\windows\system32\command.cmd")


    Still no such luck, the wierd thing is the dim a command actually worked one time and when I did it again without altering the code it didn't work, and now it never works. I have gone as far as rebooting my system to clear the memory.... Any help please?!?!?

    Thanks

    -Phil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width