Sign in to follow this  
Followers 0
PcExpert

Find a user defined number

19 posts in this topic

Hello,

Is it possible to make a program where users can search a database for a number and if that number is found then it displays a msgbox with the status of that number?

a sample:

A users runs check.exe

A Inputbox is shown

User puts in his number

Program searches for that number in the database

If the number exists it reads the next line with the status of that number and it then returns the status to the user by displaying a msgbox with the status.

Thanks for your help!

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

I already have a database I only need the to know how to search throught it.

Edited by PcExpert

Share this post


Link to post
Share on other sites

I searched in the helpfile. But I didn´t find anything, but I know that autoit can do it. Can somebody put me on the right way?

Share this post


Link to post
Share on other sites

Is the database in a text file, or INI file, because if so, you could just use on of the String functions to search through it.


[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

It's a text file (.txt)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I think StringInStr() might work

$result = StringInStr("I am a String", "RING")
MsgBox(0, "Search result:", $result)

$location = StringInStr("How much wood could a woodchuck chuck is a woodchuck could chuck wood?", "wood", 0, 3) ; Find the 3rd occurance of "wood"
Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

Show us part of the TXT file. You need to parse the database in such a way so that you can find stuff by Index. A few lines should be enough.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This is 1 problem registred in the database.

Name:Test

Problem: Computer doesn't start

Code: 56891

---------------------------

With the code I want users to be able to check the status of there problem. So users open a program input there problem code and then it returns the status of the problem with the code specified.

Edited by PcExpert

Share this post


Link to post
Share on other sites

So the database looks like this

CODE
Name:Test

Problem: Computer doesn't start

Code: 56891

Name:Test

Problem: Computer doesn't start

Code: 56891

Name:Test

Problem: Computer doesn't start

Code: 56891

Name:Test

Problem: Computer doesn't start

Code: 56891

Name:Test

Problem: Computer doesn't start

Code: 56891

Name:Test

Problem: Computer doesn't start

Code: 56891

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thats right with a line like this:

---------------------------------

after each problem

So it looks like this:

Name:Test

Problem: Computer doesn't start

Code: 56891

---------------------------------

Name:Test

Problem: Computer doesn't start

Code: 56891

---------------------------------

Name:Test

Problem: Computer doesn't start

Code: 56891

---------------------------------

Name:Test

Problem: Computer doesn't start

Code: 56891

---------------------------------

Edited by PcExpert

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Next time, give more information on what you want. You mentioned 'a' database, it could have been anything! Never make others have to find out how to help you.

#include <Array.au3>

$Read = FileRead("Database.txt")
While StringInStr($Read,"--")
    $Read = StringReplace($Read,"--","-")
WEnd

$Database = StringSplit($Read,"-")
_ArrayDisplay($Database,$Database[0])

$i = InputBox("","Code?")
For $x = 1 to $Database[0]
    If StringInStr($Database[$x],$i) Then
        MsgBox(0,"Database", $Database[$x])
    EndIf
Next
Edited by Manadar

Share this post


Link to post
Share on other sites

Thanks!

If I start it I first get a msgbox displaying:

[0]= 5

[1] = Name:Test

Problem: Computer doesn't start

Code: 56891

[2] =

Name:Test

Problem: Computer doesn't start

Code: 36271

[3] =

Name:Test

Problem: Computer doesn't start

Code: 54927

[4] =

Name:Test

Problem: Computer doesn't start

Code: 22519

[5] =

Can I get rid of that? So it only displays the second msgbox with the info?

Share this post


Link to post
Share on other sites

I forgot to remove it, I used it for testing purposes.

$Read = FileRead("Database.txt")
While StringInStr($Read,"--")
    $Read = StringReplace($Read,"--","-")
WEnd

$Database = StringSplit($Read,"-")

$i = InputBox("","Code?")
For $x = 1 to $Database[0]
    If StringInStr($Database[$x],$i) Then
        MsgBox(0,"Database", $Database[$x])
    EndIf
Next

Share this post


Link to post
Share on other sites

Thanks, it works!

Share this post


Link to post
Share on other sites

I wait one question: How to display a msgbox if the number is not found? This is what I tried:

#include <Array.au3>

$Read = FileRead("Database.txt")

While StringInStr($Read,"--")

$Read = StringReplace($Read,"--","-")

WEnd

$Database = StringSplit($Read,"-")

$i = InputBox("","Probleemcode invoeren A.U.B.")

For $x = 1 to $Database[0]If StringInStr($Database[$x],$i) Then

MsgBox(0,"Database", $Database[$x])

Else

Msgbox(64, "Database", "Number not found.")

EndIf

Next

then it displays the msgbox 3 times or so if the number is not found I want it to just show once.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

$Read = FileRead("Database.txt")
While StringInStr($Read,"--")
$Read = StringReplace($Read,"--","-")
WEnd

$Database = StringSplit($Read,"-")

$i = InputBox("","Probleemcode invoeren A.U.B.")
For $x = 1 to $Database[0]
If StringInStr($Database[$x],$i) Then
 MsgBox(0,"Database", $Database[$x])
 Exit
EndIf
Next
Msgbox(64, "Database", "Number not found.")

Now if the number is found it quits before the "Number not found" msgbox is shown. You can delete the INclude.

Edited by Manadar

Share this post


Link to post
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
Sign in to follow this  
Followers 0