4 Replies - 1028 Views - Last Post: 17 August 2012 - 12:59 AM Rate Topic: -----

#1 TheCaleb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 26-January 12

How to .ReadAll and set it to variable to read later?

Posted 15 August 2012 - 07:28 PM

Pretty much this is a simple loop that will ask someone for there phone number. When I try to verify if the area code is correct it doesn't work... I have done try'd to use the Left() function to see if it will = a string like this
If Left(HerNum,3) = "863" then
MsgBox("BLAH")
End if



that never worked so I thought about using a File System object to create a text file and then read it.. but I'm lost on how to save it to a variable to later compare if that 3 digit number is the right area code.

Here is my code so far...


On Error Resume Next
'PHONE NUMBER PLEASE :D/>
'Created by McLovin
' Create the objects that we'll be using..
Set Shell = WScript.CreateObject("WScript.Shell")
'Got to get access to them FILES :o/>
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
'This will more than likely come in handy later :D/>
Set NET = WScript.CreateObject("WScript.Network")

' Lets get our user directory
User = Shell.ExpandEnvironmentStrings("%USERPROFILE%")
'Why not grab this one too, may need it...
WindowsHome = Shell.ExpandEnvironmentStrings("%WINDIR%")
'Let get to know eacho other a little
Gname = InputBox("What's your name?", Name)
'Lets Woo her
MsgBox("What a pretty name, "+Gname)
'Set our loop
Do Until Len(HerNum) >= 10 And Len(HerNum) < 12
'Shoot to kill
 HerNum = InputBox("What is your number?")
	if Len(HerNum) <= 9 then
	MsgBox("Please enter a full 10 diget number")
	End if
'MsgBox(Mid(HerNum, 2, 1))
'We don't like fake nubers nor random numbers..
if Left(HerNum,3) <> "863" then
MsgBox'what'
End if

'Check if it is fake or not.. I could get Len() nor Left() etc to work :(/>
'Create a test file witch will get deleted
Set Cfile = FSO.CreateTextFile( User + "\Desktop\real.txt", True )
Cfile.write(Left(HerNum,3))
Cfile.Close
'Read the test file
Set Rfile = objFSO.OpenTextFile(User + "\Desktop\real.txt", 1)
ExecuteGlobal Area = Rfile.ReadAll



Rfile.close
if Area = "123" then
	MsgBoxStyle.Critical("Wrong Area Code!")
End if
 
 
 
if Len(HerNum) > 12 then 
	MsgBox'Number is too long'
End if
'if Mid(HerNum, 1, 1) <> "8" And Mid(HerNum, 2,1 ) <> "6" then
	'MsgBox'Fake numbers are not talerated!'
	'End if
loop 

'Now lets save our # in our phonebook
Set Dial = FSO.CreateTextFile( User + "\Desktop\PhoneBook.txt", True ) 
Dial.Write (Gname+"'s number is: "+HerNum)
Dial.WriteLine ("")
Dial.Close

' Clean up
Set Shell = Nothing
Set FSO = Nothing
Set NET = Nothing
' Done!






If any one could help or point me into the right direction, thanks :D

Is This A Good Question/Topic? 0
  • +

Replies To: How to .ReadAll and set it to variable to read later?

#2 TheCaleb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 26-January 12

Re: How to .ReadAll and set it to variable to read later?

Posted 15 August 2012 - 07:32 PM

The past couple of hours have been hectic trying to figure this out, so I wouldn't be surprised if there is something in my code more than once (repeated) and more than likely out of place. Thanks again :D
Was This Post Helpful? 0
  • +
  • -

#3 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: How to .ReadAll and set it to variable to read later?

Posted 15 August 2012 - 11:46 PM

What is "HerNum" variable declared as?

The following code works fine

Dim strHerNum As String

    strHerNum = "8635551234"
    
    If Left$(strHerNum, 3) = "863" Then
        ' Number Matches
        MsgBox "Match"
    Else
        ' mismatch
        MsgBox "Mismatch"
    End If

Was This Post Helpful? 0
  • +
  • -

#4 TheCaleb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 26-January 12

Re: How to .ReadAll and set it to variable to read later?

Posted 16 August 2012 - 01:43 PM

HerNum is a text box that take her number and I want to store it so I can see if the area code is the right area code. Thanks
Was This Post Helpful? 0
  • +
  • -

#5 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: How to .ReadAll and set it to variable to read later?

Posted 17 August 2012 - 12:59 AM

You have in your code HerNum = InputBox("Enter your Name"), so therefore HerNum should really be defined as a string.

Have a look at using a naming convention (google it or search here) for your variables. It will make your code so much easier to read for yourself and others.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1