Announcement

Collapse
No announcement yet.

Learning VB script!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Learning VB script!

    I'm workin on a script for changing my IP address. Question: are there variables for the function --readfile.SkipLine--? Say I want to skip 5 lines down, Do I have to use this 5 times? I tried to use it like the --readfile.Skip(31)-- function, Didnt work. I looked on web @ http://www.devguru.com/Technologies/..._skipline.html , but I found no reference...........................JG

    [This message was edited by Jebus on Tuesday, 19 February 2002 at 02:10 AM.]
    3.0.0.548: HS3PRO - 3.0.5.10: AIAlert - 2.1.1.0: APIWeather - 2.0.64.0: BLBackup - 2.0.45.0: BLLAN - 2.0.37.0: BLRoombaWifi - 1.0.0.3: DevLog - 1.2.5.15: KeyPad - 3.0.2.25: NetCAM - 0.0.0.52: Pushover 3P - 3.0.0.5: SendVFD - 1.0.0.3: Tiles - 3.0.11.0: Z-Wave

    #2
    you could use a loop...

    For n = 1 to 5
    readfile.SkipLine
    Next

    Comment


      #3
      Cool Thanks I have gotten my script to read from a text file created by using winipcfg in batch mode and then write new ip address to hs.log! WooHoo! Now my script challenge is to open my html page and insert the new IP address into the proper form reference. Another question: After I open the html file with what I believe is filesys.OpenTextFile Then do i use InStr(Start, String, Substring, Compare) to parse it?


      I guess i should cut to the chase. I am trying to parse for this line

      <form><input type="button" value="My HomeSeer" onClick="window.location.href='http://guest:guest@63.84.112.71:83'"></form>

      in my html file and replace just the IP address.
      Any Ideas? Send me in the right direction, The only way to learn is do the work........JG

      [This message was edited by Jebus on Tuesday, 19 February 2002 at 02:27 AM.]
      3.0.0.548: HS3PRO - 3.0.5.10: AIAlert - 2.1.1.0: APIWeather - 2.0.64.0: BLBackup - 2.0.45.0: BLLAN - 2.0.37.0: BLRoombaWifi - 1.0.0.3: DevLog - 1.2.5.15: KeyPad - 3.0.2.25: NetCAM - 0.0.0.52: Pushover 3P - 3.0.0.5: SendVFD - 1.0.0.3: Tiles - 3.0.11.0: Z-Wave

      Comment


        #4
        you said...
        "Any Ideas? Send me in the right direction"

        You might want to think about posting these kind of questions in the "Script Writing" or "Programming With HomeSeer" message groups. This group, "Script Library Discussion(HS)" is really more for discussing already finished scripts that people post in the new (read only) "Script Library (HS)". You'll most likely get more/faster answers in those groups, I would think.

        As to your question... my first thoughts would be to assign the entire webpage to a variable, lets say "myPage", then if the current number in the page was "63.84.112.71:83" and let say you wanted to change it to "192.168.100.18:8080", then do something like...

        newIP="192.168.100.18:8080"
        pageSize=Len(myPage)
        thisFarIn=Instr(myPage,"63.84.112.71:83")
        pageTop=Left(myPage,thisFarIn)
        pageMiddle=newIP
        pageBottom=Right(myPage, (pageSize-thisFarIn) -15)
        pageNew=pageTop & pageMiddle & pageBottom


        This is kinda big and drawn out, but better that way to get the points across. Hope it helps.

        Comment


          #5
          Create a version of your HTML file and replace href='http://guest:guest@63.84.112.71:83'
          with
          href='http://guest:guest@%%IP%%:83'
          and name it 'something.html.template'

          Now, read in the template file, search for %%IP%% and replace it with the proper IP address and then write it out to file something.html. Look up vbscript's regexp object as a nice way to search and replace text.
          ------------------------------------------------

          I have already written code to do this.
          Search the message board for 'dicfile.vbs' & download it.

          #include dicfile.vbs in your program, then load your HTML file like this:
          Bholio

          Comment


            #6
            Jake
            Ok I'll move this thread, just one more post.
            Bholio,
            Any way I can get you to check this, I'm open to all suggestions. I have your dicfile.vbs from dated december. I'm stuck. This is the log entry
            2/19/02 11:02:46 PM~!~216.64.150.167~!~
            2/19/02 11:02:46 PM~!~Error~!~Script error in file: ipchange1.txt: 53:File not found in line 293
            3.0.0.548: HS3PRO - 3.0.5.10: AIAlert - 2.1.1.0: APIWeather - 2.0.64.0: BLBackup - 2.0.45.0: BLLAN - 2.0.37.0: BLRoombaWifi - 1.0.0.3: DevLog - 1.2.5.15: KeyPad - 3.0.2.25: NetCAM - 0.0.0.52: Pushover 3P - 3.0.0.5: SendVFD - 1.0.0.3: Tiles - 3.0.11.0: Z-Wave

            Comment


              #7
              OK,
              so my example wasn't all that good. You need to specify the entire filename in the call to htmlfile.readfile. Something like

              Also, you have the call to spewfile wrong.
              Another thing which might help is if you place the include for dicfile at the end of the program instead of the beginning. That way, any errors in your program will be flagged with the proper line number. (Again, bad example)

              Bholio

              Comment


                #8
                Bholio,
                No problem, I'm happy to get the input. I'm tryin to absorb all this. I looked at your dicfile.vbs and some other template.html files and saw that everyone was keeping to the somethingTemplate.html format not something.html.template. Is this a non issue as long as you keep the continuity? Also I saw the something.config files. Is this needed. I had seen your implementation of GetAppPath in dicfile.vbs and had tried it in script cause thats where the log was pointing me. But now I realize that is listed in a seperate fucnction. I will implement your changes and I thank you for your help........................JG
                3.0.0.548: HS3PRO - 3.0.5.10: AIAlert - 2.1.1.0: APIWeather - 2.0.64.0: BLBackup - 2.0.45.0: BLLAN - 2.0.37.0: BLRoombaWifi - 1.0.0.3: DevLog - 1.2.5.15: KeyPad - 3.0.2.25: NetCAM - 0.0.0.52: Pushover 3P - 3.0.0.5: SendVFD - 1.0.0.3: Tiles - 3.0.11.0: Z-Wave

                Comment


                  #9
                  Yes this thread should be in the Script Writing Forum but might as well complete the thread here.

                  I just want to let others know that later versions of VBScript have the Replace function. It is much easier than parsing via calls to the InStr function and less clunky (but, admittedly much less powerful) than using RegExp object.

                  From VBScript Reference Guide ..

                  Replace Function returns a string in which a specified substring has been replaced with another substring a specified number of times.

                  Replace(expression, find, replacewith[, start[, count[, compare]]])

                  Arguments<UL TYPE=SQUARE>
                  <LI>expression - Required. String expression containing substring to replace.
                  <LI>find - Required. Substring being searched for.
                  <LI>replacewith = Required. Replacement substring.
                  <LI>start - Optional. Position within expression where substring search is to begin. If omitted, 1 is assumed. Must be used in conjunction with count.
                  <LI>count - Optional. Number of substring substitutions to perform. If omitted, the default value is -1, which means make all possible substitutions. Must be used in conjunction with start.
                  <LI>compare - Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values. If omitted, the default value is 0, which means perform a binary comparison.[/list]

                  Settings
                  The compare argument can have the following values:

                  Constant Value Description
                  vbBinaryCompare 0 Perform a binary comparison.
                  vbTextCompare 1 Perform a textual comparison.

                  Return Values- Replace returns the following values:<UL TYPE=SQUARE>
                  <LI>expression is zero-length - Zero-length string ("")
                  <LI>expression is Null - An error.
                  <LI>find is zero-length - Copy of expression.
                  <LI>replacewith is zero-length - Copy of expression with all occurences of find removed.
                  <LI>start &gt; Len(expression) - Zero-length string.
                  <LI>count is 0 - Copy of expression.[/list]

                  My second comment is that you may want to subscribe to a free dynamic IP mapping service(e.g., http://www.no-ip.com) that will map you IP to a domain name thereby allowing you to always have a reference to your IP address. You would need to have a very small program installed that periodically connects to the internet to update IP. I tried scripts to change IP address and the problem is you need your IP address to access you web page to see your new IP address.

                  Jim Doolittle
                  Jim Doolittle

                  My Twitter
                  My Hardware & Software

                  Comment


                    #10
                    Jebus,
                    The name of the template files does not matter. I usually use somethingTemplate.html, but it doesn't matter. You can call the template file 'fred' if you want. The advantage of somethingtemplate.html is that you can load it into a web browser to get a feel for how it will look, whereas loading something.html.template might not work in the browser since it is missing the html extension.

                    dicFile.vbs is actually a collection of utilities. One of the things it does is the template file stuff. Another thing it does which is totally unrelated is the config file stuff.

                    The readfile code requires you to supply the entire path. So you must call GetAppPath yourself. Looking at the code, it appears that at one time readfile did call GetAppPath for you (it's commented out now however).

                    Bholio

                    Comment


                      #11
                      Bholio'
                      Success! I modified the script and more. It is complete, Updates website w/wsftp program thru command line. I could not get HS.FTP to login with my username. Oh well. I use wsftp alot and this way works great. I even get a little chirp when it completes. Thank You. It's great that everyone on this Board is willing to help someone learn. Hats off to ALL. [img]/infopop/emoticons/icon_cool.gif[/img] Ok on to the next project. Giving custom_cnn.txt a clickable link.
                      HS.RULES.......JG
                      3.0.0.548: HS3PRO - 3.0.5.10: AIAlert - 2.1.1.0: APIWeather - 2.0.64.0: BLBackup - 2.0.45.0: BLLAN - 2.0.37.0: BLRoombaWifi - 1.0.0.3: DevLog - 1.2.5.15: KeyPad - 3.0.2.25: NetCAM - 0.0.0.52: Pushover 3P - 3.0.0.5: SendVFD - 1.0.0.3: Tiles - 3.0.11.0: Z-Wave

                      Comment

                      Working...
                      X