5 Replies - 2284 Views - Last Post: 19 December 2011 - 09:01 PM Rate Topic: -----

#1 saren   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-January 11

a logic function in Visual basic 6.0 finding a string within a string

Posted 18 December 2011 - 11:46 AM

We are creating a chat bot that would recognize or at least get hints from a text string encoded by the user and we will be setting constants that would be the output once a specific text string is found within the entry made by the user.

We are using excel programming before and the syntax used should be like this.

=IF(ISNUMBER(SEARCH("hi",$A$1)),hello",C2)

using this syntax in excel, it will find the word "hi" within the text string found in cell A1 (for example the text string contains "hi, i am the king of the world"), and if it finds it (true condition), it will show "hello" (value if true), else it will run another if statement in cell C2 (value if false).

the thing now is that this kind of syntax is not working in visual basic. Is there a function in Visual basic that can be used that would show the same result as what we used in excel?

Is This A Good Question/Topic? 0
  • +

Replies To: a logic function in Visual basic 6.0 finding a string within a string

#2 maj3091   User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 2,005
  • Joined: 26-March 09

Re: a logic function in Visual basic 6.0 finding a string within a string

Posted 18 December 2011 - 12:03 PM

You can use the IIF function


variable = IIF(statement is true, TruePart, FalsePart)

Was This Post Helpful? 0
  • +
  • -

#3 saren   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-January 11

Re: a logic function in Visual basic 6.0 finding a string within a string

Posted 18 December 2011 - 12:23 PM

View Postmaj3091, on 18 December 2011 - 12:03 PM, said:

You can use the IIF function


variable = IIF(statement is true, TruePart, FalsePart)

thanks for replying, but I don't know that syntax/code can you give me an example to use that? or how to use that syntax/code?
thanks :)

This post has been edited by saren: 18 December 2011 - 12:24 PM

Was This Post Helpful? 0
  • +
  • -

#4 BobRodes   User is offline

  • Product Manager
  • member icon

Reputation: 601
  • View blog
  • Posts: 3,072
  • Joined: 19-May 09

Re: a logic function in Visual basic 6.0 finding a string within a string

Posted 18 December 2011 - 12:51 PM

Seriously? http://msdn.microsof...4(v=vs.60).aspx
Was This Post Helpful? 0
  • +
  • -

#5 saren   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-January 11

Re: a logic function in Visual basic 6.0 finding a string within a string

Posted 18 December 2011 - 01:47 PM

View PostBobRodes, on 18 December 2011 - 12:51 PM, said:


thanks for the link, oh i see, IIF function is an alternative IF then else statement right?

I use If then then statement before like this:

If Text1.Text = "hi" Then
    Text2.Text = "hello"
Else
    Text2.Text = "what?"
End If



but I don't know how to detect a word from the text, like

text1.text = "hi, how are you?"

I just want to detect the word "hi" from the sentence "hi, how are you?"

is that possible?
because if I use the if then statement it will display the false part,

by the way, I wan't to create a chatbot from that, is that possible? or another way to create chatbot more easier?
thanks

(Sorry for my poor explanation/English)
Was This Post Helpful? 0
  • +
  • -

#6 BobRodes   User is offline

  • Product Manager
  • member icon

Reputation: 601
  • View blog
  • Posts: 3,072
  • Joined: 19-May 09

Re: a logic function in Visual basic 6.0 finding a string within a string

Posted 19 December 2011 - 09:01 PM

Here's a link to the VB6 Reference library: http://msdn.microsof...(v=VS.60).aspx. It's a little hard to find, so bookmark this. Then, investigate the instr, instrrev, mid, left, and right functions.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1