Jump to content

Working around with Array for the 1st time


Go to solution Solved by BrewManNH,

Recommended Posts

Hello everyone.

I started working on a little tool to help me with my work (data entry), now the tool is finished and our organization will be sharing this tool with other organizations, to protect myself and my organization i decided to make a simple login for this tool, not into fancy stuff so i tried to make it as simple as possible using a method i implemented inside the tool.

The following script is a part of the tool, it works like charm

_FileCreate(@DocumentsCommonDir & "\Temp.txt")
Local $iPleaseWait = _IEGetObjById($oIE, "ctl00_panelUpdateProgress")
IniWrite(@DocumentsCommonDir & "\Temp.txt", "Temp", "Temp Text", $iPleaseWait.innerhtml)
While 1
    $Read = FileRead(@DocumentsCommonDir & "\Temp.txt")
    IniWrite(@DocumentsCommonDir & "\Temp.txt", "Temp", "Temp Text", $iPleaseWait.innerhtml)
    Local $aDays = StringSplit($Read, '="')
    For $i = 1 To $aDays[0]
        If $aDays[$i] = "true" Then
            FileDelete(@DocumentsCommonDir & "\Temp.txt")
            ExitLoop (2)
        ElseIf $aDays[$i] = "false" Then

            Sleep(100)
            FileDelete(@DocumentsCommonDir & "\Temp.txt")
        EndIf
    Next
WEnd
FileDelete(@DocumentsCommonDir & "\Temp.txt")

 

The code posted above simply checks for the "Please Wait" hidden status and reacts according, to apply the same technique with the login i made this script:

#include <MsgBoxConstants.au3>
#include <InetConstants.au3>
#include <file.au3>


Example()

Func Example()
    Local $bData = InetRead("http://www.mosalame.co.nf/MuhammadSal.dat", $INET_FORCERELOAD)
    Local $sData = BinaryToString($bData)
    _FileCreate(@DocumentsCommonDir & "\user.dat")
    IniWrite(@DocumentsCommonDir & "\user.dat", "", "", $sData)
        $Read = FileRead(@DocumentsCommonDir & "\user.dat")
        Local $aDays = StringSplit($Read, "=")
        For $i = 1 To $aDays[0]
            If $aDays[$i] = "Anas" Then
                MsgBox($MB_SYSTEMMODAL, "", "success")
                ExitLoop
            EndIf
            MsgBox($MB_SYSTEMMODAL, "", "$aDays[" & $i & "] - " & $aDays[$i])
        Next
EndFunc

 

From my simple understanding of AutoIt the 2nd script should do the exact same job as the 1st one, everything works except that it doesn't exit the loop, $aDays[2] value is "Anas" as you can see in the message box, but the script simply doesn't give a message box saying "success" or exit the loop, what did i do wrong here? some help would be much appreciated.

Link to comment
Share on other sites

Hi,

First thing is you're not using the Ini functions correctly.

Your ini file must have a Section and keys.

[section1]
key1=value1
key2=value2

;your ini (.dat) is:
Anas
=MuhamdSal
=Habla

;so the section is missing brackets and the keys are missing
;I guess it should be like :
[logins]
MuhamdSal=password1
Habla=password2

Take a look at the helpfile and come back with what you've done if you need some help ;)

Br, FireFox.

Link to comment
Share on other sites

Hi,

First thing is you're not using the Ini functions correctly.

Your ini file must have a Section and keys.

[section1]
key1=value1
key2=value2

;your ini (.dat) is:
Anas
=MuhamdSal
=Habla

;so the section is missing brackets and the keys are missing
;I guess it should be like :
[logins]
MuhamdSal=password1
Habla=password2

Take a look at the helpfile and come back with what you've done if you need some help ;)

Br, FireFox.

 

Thank you for the quick reply, I understand how iniwrite/iniread works, as you can see in the 1st code snippet, at my login attempt i kinda started testing anything and everything to get it to work and still failed, adding section and key doesn't change a thing in it.

Link to comment
Share on other sites

#include <MsgBoxConstants.au3>
#include <InetConstants.au3>
#include <file.au3>


Example()

Func Example()
    Local $bData = InetRead("http://www.mosalame.co.nf/MuhammadSal.dat", $INET_FORCERELOAD)
    Local $sData = BinaryToString($bData)
    _FileCreate(@DocumentsCommonDir & "\user.dat")
    IniWrite(@DocumentsCommonDir & "\user.dat", "Temp", "Temp Text", $sData)
        $Read = FileRead(@DocumentsCommonDir & "\user.dat")
        Local $aDays = StringSplit($Read, "=")
        For $i = 1 To $aDays[0]
            If $aDays[$i] = "Habla" Then
                MsgBox($MB_SYSTEMMODAL, "", "success")
                ExitLoop (3)
                Exit
            EndIf
            MsgBox($MB_SYSTEMMODAL, "", "$aDays[" & $i & "] - " & $aDays[$i])
        Next
EndFunc
Link to comment
Share on other sites

  • Solution

Don't use IniWrite if all you want to do is write the contents of the $sData variable to a file, use FileWrite instead. You say you know IniWrite works, and then demonstrate that you don't even need it.

Actually, you don't even need to write the data to a file at all, you could use StringInStr on the $sData variable to see if the text you're looking for is there.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Don't use IniWrite if all you want to do is write the contents of the $sData variable to a file, use FileWrite instead. You say you know IniWrite works, and then demonstrate that you don't even need it.

Actually, you don't even need to write the data to a file at all, you could use StringInStr on the $sData variable to see if the text you're looking for is there.

 

"simple understanding of AutoIt", I use whatever does the job for me, iniwrite/iniread did the job with the "Please Wait" issue, so I used it again, I did say that i know how it works, i didn't say that I know better ways to do it.

That being said, I tried with the StringInStr "using it for the 1st time too", it it seemed to do exactly what i needed, here is how i did it

#include <MsgBoxConstants.au3>
#include <InetConstants.au3>
#include <file.au3>

Example()

Func Example()
    Local $bData = InetRead("http://www.mosalame.co.nf/MuhammadSal.dat", $INET_FORCERELOAD)
    Local $sData = BinaryToString($bData)
    Local $lUser= StringInStr($sData, "Habla")
    If $lUser= "0" Then
        MsgBox(0, "", "Invalid")
    Else
        MsgBox(0, "", "Success")
    EndIf
EndFunc

 

Thank you!

Just to clarify, what are the datas in the dat file? logins?

What BrewManNH said.

 

the data in the dat file will be usernames which i will be making for people who wants to use the tool, if the username is in the .dat file the tool will start, else the tool will exit.

Link to comment
Share on other sites

the data in the dat file will be usernames which i will be making for people who wants to use the tool, if the username is in the .dat file the tool will start, else the tool will exit.

Alright :)

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...