forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Reading from file, parsing and adding to list
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Wed May 14, 2003 11:55 pm    Post subject: Reading from file, parsing and adding to list Reply with quote

I'm trying to read some data from a text file.
I've managed that. Well, sort of Laughing

Anyways, I also want to parse that data which looks like this:
Google|http://www.google.com
Yahoo|http://www.yahoo.com

Then I want to add the names (Google, Yahoo, etc) to a list object.
I managed that too. But when I tried to parse it all and add the names I messed it up.

When I click a button I want to start a search query using the selected search site. Here is the code I got now. I haven't really used the LIST thing much. But I'm more than willing to learn.

Code:
LIST CREATE, 1, SORTED
LIST LOADFILE,1,urls.txt
rem binfile open,1,urls.txt,read

  DIALOG CREATE,List Experiment,-1,0,401,178
REM *** Modified by Dialog Designer on 15.05.2003 - 01:33 ***
  DIALOG ADD,LIST,LIST1,8,8,384,112
  DIALOG ADD,STATUS,STATUS1,There are @COUNT(1) names in the list
  DIALOG ADD,EDIT,EDIT1,136,8,176,19
  DIALOG ADD,BUTTON,SEARCH,128,192,64,24,Search
  DIALOG SHOW



while @not(@binfile(EOF,1))
  parse "%N;%U",@next(1)
  %N = @trim(%N)
  %U = @trim(%U)
  LIST ASSIGN,LIST1,%N
wend


:Evloop
wait event
goto @event()

:SEARCHBUTTON
  %K = @dlgtext(EDIT1)
  SHELL OPEN,%U
goto Evloop

:Close
Exit

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Thu May 15, 2003 12:48 am    Post subject: Reply with quote

You're going to need to use the LIST command entirely if you are not using
BINFILE. For this task I would recommend using the LIST command. Smile

I will explain further tomorrow unless someone else does before that.
I don't have time to to that now.

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Thu May 15, 2003 1:02 am    Post subject: Reply with quote

Well, I'm not sure how to.
I'm guessing that I need to use a while statement and add the parsing inside that statement, and then assign the first variable from the parsed data into the list...

I've managed to get the first item from the list inside the list, and also the last one when I used @next(1) but I'm really not sure exactly how that works either.

Also, I need to replace a certain string inside the url, which is in my list %K

As you can see the @dlgtext functions gets the text the user types in and I want to put that value inside the %K variable before it is sent to the browser with the SHELL command.

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Thu May 15, 2003 1:12 am    Post subject: Reply with quote

OK... Try this:

Code:
LIST CREATE, 1, SORTED
LIST LOADFILE,1,urls.txt

  DIALOG CREATE,List Experiment,-1,0,401,178
  DIALOG ADD,LIST,LIST1,8,8,384,112
  DIALOG ADD,STATUS,STATUS1,There are @COUNT(1) names in the list.
  DIALOG ADD,EDIT,EDIT1,136,8,176,19
  DIALOG ADD,BUTTON,SEARCH,128,192,64,24,Search
  DIALOG SHOW

%%index = 0
repeat
parse "%%NAME;%%URL",@item(1, %%index)
list add,list1,%%NAME
warn Name: %%NAME@cr()URL: %%URL
%%index = @succ(%%index)
until @equal(%%index, @count(1))


:Evloop
dialog set,status1,There are @COUNT(1) names in the list.
wait event
goto @event()

:SEARCHBUTTON
if @match(list1, @dlgtext(edit1))
  WARN There is a match at index number @index(list1)
end
goto Evloop

:Close
Exit

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Thu May 15, 2003 1:21 am    Post subject: Reply with quote

I still can't get it working.
The line for Yahoo looks like this in the text file:
Yahoo|http://search.yahoo.com/bin/search?p=%K

where the %K is, is where I want the value from the variable %K to be inserted so if I type in GeoTrail and press the button after selecting Yahoo in the list, it will open the browser to this url http://search.yahoo.com/bin/search?p=GeoTrail

Code:
LIST CREATE, 1, SORTED
LIST LOADFILE,1,urls.txt

  DIALOG CREATE,List Experiment,-1,0,401,178
  DIALOG ADD,LIST,LIST1,8,8,384,112
  DIALOG ADD,STATUS,STATUS1,There are @COUNT(1) names in the list.
  DIALOG ADD,EDIT,EDIT1,136,8,176,19
  DIALOG ADD,BUTTON,SEARCH,128,192,64,24,Search
  DIALOG SHOW

%%index = 0
repeat
parse "%%NAME;%%URL",@item(1, %%index)
list add,list1,%%NAME
rem warn Name: %%NAME@cr()URL: %%URL
%%index = @succ(%%index)
until @equal(%%index, @count(1))


:Evloop
dialog set,status1,There are @COUNT(1) names in the list.
wait event
goto @event()

:SEARCHBUTTON
rem if @match(list1, @dlgtext(edit1))
rem  WARN There is a match at index number @index(list1)
%K = @dlgtext(edit1)
SHELL OPEN,%%URL
rem end
goto Evloop

:Close
Exit


Isn't there a simple string replace command in VDS?

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
cnodnarb
Professional Member
Professional Member


Joined: 11 Sep 2002
Posts: 766
Location: Eastman, GA

PostPosted: Thu May 15, 2003 2:09 am    Post subject: Reply with quote

Logic error.

No variable needs stored in the actual text file, the listings should just end w/o variable specs.

Inside text file: Yahoo|http://search.yahoo.com/bin/search?p=

main line #32
SHELL OPEN,%%URL""%K

If you have the search variable embedded in two strings this is more complicated, but still very simple in VDS.

Parse to three variables and tack the last on on the end and shell as before.

NodNarb

Its late and I just had some teeth pulled today, forgive me if this makes no friggin' sense whatsoever.
Back to top
View user's profile Send private message AIM Address
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Thu May 15, 2003 2:18 am    Post subject: Reply with quote

Yeah, I know that.
But in this case I wanted to use the %K as a word to be replaced by the %K variable.

Some of the search engines requires a string like
search.php?query=geotrail&language=eng
(search.php?query=%K&language=eng)

so I really should be able to put the variable inside the url string.

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Thu May 15, 2003 3:16 am    Post subject: Reply with quote

Maybe I'm not understanding what you want, but it should be as easy as:
Code:

REM Selected Search Engine Here.
%%Search = Yahoo|http://search.yahoo.com/bin/search?p=

REM Inputted Search Term Here.
%%SearchTerm = GeoTrail

PARSE "%%Name;%%URL",%%Search
%%NewURL = %%URL%%SearchTerm
SHELL OPEN,%%NewURL
INFO Searching %%Name for: %%SearchTerm

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
cnodnarb
Professional Member
Professional Member


Joined: 11 Sep 2002
Posts: 766
Location: Eastman, GA

PostPosted: Thu May 15, 2003 4:27 am    Post subject: Reply with quote

Fine. Then change file format like this

urls.txt
Code:

Search|http://search.php?query=|%K|&language=eng
Yahoo|http://search.yahoo.com/bin/search?p=|%K


Code:

LIST CREATE, 1, SORTED
LIST LOADFILE,1,urls.txt

  DIALOG CREATE,List Experiment,-1,0,401,178
  DIALOG ADD,LIST,LIST1,8,8,384,112
  DIALOG ADD,STATUS,STATUS1,There are @COUNT(1) names in the list.
  DIALOG ADD,EDIT,EDIT1,136,8,176,19
  DIALOG ADD,BUTTON,SEARCH,128,192,64,24,Search
  DIALOG SHOW

%%index = 0
repeat
rem note %%k is different than %k
parse "%%NAME;%%URL;%%K;%%URL2",@item(1, %%index)
list add,list1,%%NAME
rem warn Name: %%NAME@cr()URL: %%URL"%K"%%URL2
%%index = @succ(%%index)
until @equal(%%index, @count(1))


:Evloop
dialog set,status1,There are @COUNT(1) names in the list.
wait event
goto @event()

:SEARCHBUTTON
if @equal(@index(list1),-1)
warn Please select a search engine
goto evloop
else
end
list seek,1,@index(list1)
parse "%%NAME;%%URL;%%K;%%URL2",@item(1)

%K = @dlgtext(edit1)
SHELL OPEN,%%URL""%K""%%URL2
rem end
goto Evloop

:Close
Exit


Thank you for taking my mind off of the pain of my mouth from teeth.

Somebody think of another puzzle quick!

NodNarb
Back to top
View user's profile Send private message AIM Address
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Thu May 15, 2003 7:26 am    Post subject: Reply with quote

cnodnarb wrote:

Thank you for taking my mind off of the pain of my mouth from teeth.

Somebody think of another puzzle quick!


Right - here's a couple:

Code:
What is the difference between a hangover and childbirth?

What's the difference between hard and light?


Big Smile

Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Thu May 15, 2003 1:43 pm    Post subject: Reply with quote

Yes,
thank you so much cnodnarb.

That was exactly what I was trying to do. And now it works perfectly. Thanks again Smile

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Thu May 15, 2003 4:09 pm    Post subject: Reply with quote

I got another question here on the same subject.

When a user does a search with one of the engines, the last used engine in save in the registry.

When the user starts the program, it reads the last used engine name from the registry and I want to make that the selected engine in the combo list.

I've tried everything I think.
Code:
DIALOG SET,Engines,%%Engine

Code:
LIST PUT,Engines,%%Engine


I can't get any of the to work. The last used engine is stored in the %%Engine variable. I've tested the var and it does contain the last used engine and is not empty. I have also tried to turn off SORTED on the list, but still no go Crying or Very sad

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
cnodnarb
Professional Member
Professional Member


Joined: 11 Sep 2002
Posts: 766
Location: Eastman, GA

PostPosted: Thu May 15, 2003 4:27 pm    Post subject: Reply with quote

Bah. I rarely use the registry, personal preference. Here is how I would do it with ini. How many programs have enough settings info over 64 k anyway?

Code:

rem start
inifile open,@path(%0)search.ini


rem init prior to evloop
%%read = @iniread(search,index)
if %%read
list seek,list1,%%read
end


:close
inifile write,search,index,@index(list1)


NodNarb
Back to top
View user's profile Send private message AIM Address
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Thu May 15, 2003 4:46 pm    Post subject: Reply with quote

cnodnarb wrote:
Bah. I rarely use the registry, personal preference. Here is how I would do it with ini. How many programs have enough settings info over 64 k anyway?
NodNarb


Hi cnodnarb,
Hmmm, you must have alot of really small INI files floating around on your harddrive. I'll bet if you converted all those small files to registry settings then it would free up alot of space on your harddrive but maybe you have a 250GB harddrive and you don't worry about space anymore? Multiple small files can be greater than one large file. Not to mention the fact that the registry is a database and will load into a memory mapped file so the amount of drive IO will drop tremendously as compared to opening and closing small INI files all the time. Anyway my personal preference is to use the registry because it is more efficient than using INI files.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Thu May 15, 2003 4:58 pm    Post subject: Reply with quote

I guess that's a matter of preference.
I prefer to use the registry.

Anyways, I didn't quite understand how that code can help me.

When I run the program, nothing is selected in the combo box where the %%NAME is added from the file.

And if there is a search engine name that fits in the list, I want that name selected in the combobox.

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group