Jump to content

How to import data to make changes


Recommended Posts

I have been away for a very long,long time and now I am back as a newbie. I would like to know how to read a text file for data input.

Here is what I need in a nutshell. As a tester I need to on a daily basic set up an I.P. address for a "crossover" communication and then back to the default address.

I am thinking two files; 1. the main .exe file that reads a text file that has the addresses:

1. default for normal network that has just the default ip address and subnet address.

and

2. crossover address with it own ip and subnet address.

The exe will have only two buttons to make the change by reading the text file and using the mouse click on the network icon to make the changes . Each PC will have the same exe file with a different address file.

What is the best way of doing this?

Again, I consider myself a born again programmer with no experience. Thanks ahead of time for all who might be able to help me out here.

 

Link to comment
Share on other sites

  • Moderators

I would like to know how to read a text file for data input.

Look at FileRead, or FileReadLine in the help file.

The exe will have only two buttons to make the change by reading the text file and using the mouse click on the network icon to make the changes .

Look in the help file under GUICtrlCreateButton for an example on setting up a small GUI with your two buttons.

If you get stuck, post what you have (even if it is not working the way you would like it to) and we will do our best to assist. 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks JLogan, you got me started.

fix >>I am including my code. My problem now is how to read a text file that has the IP address and subnet address and to make the changes in the IP management.

OK, I can read the file, only thing left to do -

How do I make the changes in the network management ???

Include both files (au3 and the txt file) if someone can help me out here and I should be done after some cleanup.

Again, thanks for the help.

 

ip -1.au3

PC address.txt

Edited by dew
changes in the files
Link to comment
Share on other sites

For this task a simple INI file might be the most easy way to solve your task:

 

#include <array.au3>

#cs
save these lines as "scriptname.ini"

[my-hostname]
IP=10.20.30.40
mask=255.255.0.0
gate=10.20.99.99

[another-hostname]
IP=192.168.1.100
mask=255.255.255.0
gate=192.168.1.254
#ce


$ini=StringTrimRight(@ScriptFullPath,3) & "ini"

if not FileExists($ini) Then
    MsgBox(48,"ini file not found","The required INI file is missing:" & @CRLF & @CRLF & _
    $ini)
    Exit
EndIf


$aSections=IniReadSectionNames($ini)
ArrayDisplay($aSections,"List of HostNames covered in this INI")


$found=False
for $i = 1 to $aSections[0]
    if $aSections[$i]=@ComputerName Then
        $found = True
        ExitLoop
    EndIf
Next

if not $found Then
    MsgBox(48,"Missing Entry for your Computer","There is no section for your computer:" & @CRLF & @CRLF & _
    @ComputerName)
    Exit
EndIf

$default="-ERROR-"
$Key="IP"
$IP=IniRead($ini,@ComputerName,$Key,$default) ; error checking by examining $IP for $default

$Key="Mask"
$Mask=IniRead($ini,@ComputerName,$Key,$default)


$Key="Gate"
$Gate=IniRead($ini,@ComputerName,$Key,$default)


MsgBox(0,"Info","Computer = " & @ComputerName & @CRLF & _
    "IP = " & $IP & @CRLF & _
    "Mask = " & $Mask & @CRLF & _
    "Gate = " & $Gate)

Regards, Rudi.

Edited by rudi
added the missing "ArrayDisplay()" line

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Rudi,

Thanks, I will give this a try and let you know. I have been moved to a different task for next week or so.

After looking at it, how do I select between the addresses?

Edited by dew
get a better understanding of the code
Link to comment
Share on other sites

  • Moderators

Or, if you are truly cycling only between two IPs, and you don't expect it to change often, skip the text file altogether and just include it in your script.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I am cycling between two IPs a lot (testing), with 6+ PCs and different IPs (one set of two IPs for each PC, so there is no conflict on addresses). This is the main reason for the text file or as Rudi says "a simple INI file to keep everything under control. But the main thing is to be able to go back and forth.

Hey Guy! Thanks for the support.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...