Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Input Question -PLEASE HELP-

Author
Message
Game Guy
15
Years of Service
User Offline
Joined: 9th Oct 2008
Location:
Posted: 14th Jan 2009 01:44
Hi. I'm not good at programming yet. And I want to write a simple input program that when I write a name in the input then search results are printed. But I'm stuck on the Input Command.What code is it that prints something when a certain word is typed in.

Example:

Input "typed word" Print Search results

Please help out and put in in that format. And type typed work where I need to type the word and how to print things if it is entered.

Thank You!

Zab Productions Game and Program Company.
puppyofkosh
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 14th Jan 2009 02:24
I believe there is an index of commands somewhere but it should be something like "INPUT variablename"
May0naise
15
Years of Service
User Offline
Joined: 16th Nov 2008
Location: Lost in Time
Posted: 14th Jan 2009 02:47 Edited at: 14th Jan 2009 03:00
I'd be glad to take a shot at this =)

First, say you want to ask something like..


If you don't already know, Print is used to print text on the screen, PRINT "What you want goes here in quotes"

-If you want to have someone input something then:


This basically is, Input-Shows you want someone to type a word/number/phase...
You can print things just like a print statement in the quotes
The Variable means your storing something in it, if its a number, you can just use something like Var, or Num, but if you want to use any letters you need to put an $ after the word. the $ tells DarkBasic that the Variable is a string. Strings store letters. So you would type something like Search$, or Var$.

What if i want DB to do something if someone types what i want them to say?

Well basically you use an If..Endif statement, Basically, a statement saying if one thing happens, do this. You would use it like this.


Basically, this code will ask what does a dog say? then check that if what the person typed is Woof. The person has to type Woof exactly as it is or it doesn't work.
For If statements, you always start with:
If (condition). In the preceding examply, the condition was if the person typed Woof, then it would print "Thats Correct..." To end an If statement, you use the Endif command.

Now There is a command Else, but you shouldn't need it.

so if you were making a type os search program, you could start like this:


With Input "",Search$ , it will not print anything, but will just make your input on a different line =)


Hope I helped =P
May0

Who you chose to be around you, lets you know who you are.
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 14th Jan 2009 02:56 Edited at: 14th Jan 2009 03:10
May0naise, that code won't function. Specifically, your If statements aren't going to operate the way you expect them to. Take a look at this code:



That code is not going to check if answer$ equals "Woof". Woof is going to be treated as a non-existent integer variable and declared on the spot as such, so you're essentially comparing answer$ with the number 0.

Game Guy:

Basically, you're going to use Input to get user input:



That code will accept input from the user and store it in Name$.

Now you want to compare it with other names to create the "search-style" thing you're looking for:



However if you plan on having many names you may not want to have separate variables for each person.

This is where arrays come in handy. An array is basically a list of variables, which can be accessed with numbers. The following code creates an array that can hold 10 variables, or elements:



And you set and access the elements like so:



So you can take input, then loop through these names and check against each, rather than checking against each individually:



May0naise
15
Years of Service
User Offline
Joined: 16th Nov 2008
Location: Lost in Time
Posted: 14th Jan 2009 02:59 Edited at: 14th Jan 2009 02:59
Haha sorry, well im still pretty new too lemme correct them, they should have quotes around them.

Was it good otherwise? =)

Who you chose to be around you, lets you know who you are.
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 14th Jan 2009 03:02
Quote: "Was it good otherwise? =)"


Ya, it looked fine besides that. I'm going to expand on my post a bit just to give him a better idea of what to do.

May0naise
15
Years of Service
User Offline
Joined: 16th Nov 2008
Location: Lost in Time
Posted: 14th Jan 2009 03:04
Yours is simpler then myn, i'd love to see you make a dictionary =P
rofl i might laugh if you did though

Good though =)

Who you chose to be around you, lets you know who you are.
Tom0001
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location:
Posted: 14th Jan 2009 13:32
Just to suggest an alternative method, there was something like this in the Hangman example of Hands on DarkBASIC Pro Volume 1.

Anyway, one way to do it would be to use a bunch of DATA and READ statements. For example:



Game Guy
15
Years of Service
User Offline
Joined: 9th Oct 2008
Location:
Posted: 15th Jan 2009 22:43
Ok. With two of them it exited out when I pressed enter. It was Tom's and May's. But Andrews was good.

For this I was planning on making a program for my Advertising website. so people could browse through websites and stuff. But I'm still a little confused.

If some one could come up with a working code for this it would be great.

It would start like this

Print "Enter Key Word for Website"
INPUT "" , Websearch$
DIM Website( 10 ) as Strings
Website( 1 ) = "http://web1.com"
Website( 2 ) = "http://web2.com"
Website( 3 ) = "http://web3.com"
ETC.
IF Websearch$ = Website( 1 )
print "Visit http://web1.com for web stuff"

ETC. Would that work?

Zab Productions Game and Program Company.
May0naise
15
Years of Service
User Offline
Joined: 16th Nov 2008
Location: Lost in Time
Posted: 16th Jan 2009 01:39
Alright, with myn, if you put wait key at the end, right after end if, or maybe before, i m not at home atm i think i'll post it later. Because what my code is doing is printing the awnser very fast then exiting out of the program.

anyway, about you question, to me, it looks like it would work, but i really need to learn about arrays more, so you should probobly wait for someone more experience to help. =)

Who you chose to be around you, lets you know who you are.

Login to post a reply

Server time is: 2024-09-28 00:19:38
Your offset time is: 2024-09-28 00:19:38