Connecting Tech Pros Worldwide Forums | Help | Site Map

Mad Libs-style program problem?

Alice
Guest
 
Posts: n/a
#1: Nov 20 '05
Hi -- I am trying to code a "mad libs" style program, in
which the user puts in nouns, adjectives, etc., into text
boxes. Then the user clicks on a button which opens a
message box. Inside the message box is a story with blanks
filled in by what the user entered into the text boxes.

Only when my message box opens, it does not plug in the
user's words.

Can anyone tell me what I'm doing wrong, or does anyone
have a sample of this kind of code?

Many thanks!


Bernie Yaeger
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Mad Libs-style program problem?


Hi Alice,

Sounds pretty simple - you just want to search and replace in a large
string. Please show us your code - specifically the code that parses the
long string - and I'm sure someone here can help.

HTH,

Bernie Yaeger

"Alice" <anonymous@discussions.microsoft.com> wrote in message
news:05dc01c3bb8c$96f8a900$a101280a@phx.gbl...[color=blue]
> Hi -- I am trying to code a "mad libs" style program, in
> which the user puts in nouns, adjectives, etc., into text
> boxes. Then the user clicks on a button which opens a
> message box. Inside the message box is a story with blanks
> filled in by what the user entered into the text boxes.
>
> Only when my message box opens, it does not plug in the
> user's words.
>
> Can anyone tell me what I'm doing wrong, or does anyone
> have a sample of this kind of code?
>
> Many thanks!
>[/color]


Alice
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Mad Libs-style program problem?


Thanks for responding.

Here is my code:

Public Class frmStoryGenerator
Inherits System.Windows.Forms.Form


' Declare variables for user input text boxes

Dim gstrSetting As String
Dim gstrActivity As String
Dim gstrVillain As String
Dim gstrPluralNoun1 As String
Dim gstrPluralNoun2 As String
Dim gstrAdj1 As String
Dim gstrAdj2 As String
Dim gstrAdj3 As String
Dim gstrAnimal As String
Dim gstrCountry As String
Dim gstrVerbIng1 As String
Dim gstrVerbIng2 As String
Dim gstrTimeOfYear As String

' Generate story in a message box

Private Sub btnStory_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnStory.Click


txtSetting.Text = gstrSetting
txtTimeOfYear.Text = gstrTimeOfYear
txtActivity.Text = gstrActivity
txtVillain.Text = gstrVillian
txtPluralNoun1.Text = gstrPluralNoun1
txtPluralNoun2.Text = gstrPluralNoun2
txtAdj1.Text = gstrAdj1
txtAdj2.Text = gstrAdj2
txtAdj3.Text = gstrAdj3
txtAnimal.Text = gstrAnimal
txtCountry.Text = gstrCountry
txtVerbIng1.Text = gstrVerbIng1
txtVerbIng2.Text = gstrVerbIng2

MessageBox.Show("Once, when I was in " &
gstrSetting & " in " & gstrTimeOfYear _
& ", I was out " & gstrActivity & " and came across a " &
gstrAdj1 & " sight. Of course, I was alone " _
& " at the time, so I had to face the danger alone. Though
it was a " & gstrAdj2 & " situation, I dove right in." _
& gstrVillain & " was trying to take over the world by " &
gstrVerbIng1 & gstrPluralNoun1 & ". The scheme" _
& " had to be stopped. But there were " & gstrAdj2 & " " &
gstrAdj3 & " in the way, not to mention voracious" _
& gstrPluralNoun2 & ". Still, it was all up to me to stop
it. I was victorious by " & gstrVerbIng2 & " into a large"
_
& " lake full of " & gstrAnimal & " and wrestling them all
while single-handedly convincing the local superhero of " _
& gstrCountry & " to step in and help. We started to
drive " & gstrVillian & " away. But just then, the
superhero " _
& " turned to wood, so it was all up to me. I stuffed the
villian into a large gunnysack and launched him to the
moon." _
& "Believe me, it happened. It's true." _
& " Really. The End.")

End Sub


End Class
[color=blue]
>-----Original Message-----
>Hi Alice,
>
>Sounds pretty simple - you just want to search and[/color]
replace in a large[color=blue]
>string. Please show us your code - specifically the code[/color]
that parses the[color=blue]
>long string - and I'm sure someone here can help.
>
>HTH,
>
>Bernie Yaeger
>
>"Alice" <anonymous@discussions.microsoft.com> wrote in[/color]
message[color=blue]
>news:05dc01c3bb8c$96f8a900$a101280a@phx.gbl...[color=green]
>> Hi -- I am trying to code a "mad libs" style program, in
>> which the user puts in nouns, adjectives, etc., into[/color][/color]
text[color=blue][color=green]
>> boxes. Then the user clicks on a button which opens a
>> message box. Inside the message box is a story with[/color][/color]
blanks[color=blue][color=green]
>> filled in by what the user entered into the text boxes.
>>
>> Only when my message box opens, it does not plug in the
>> user's words.
>>
>> Can anyone tell me what I'm doing wrong, or does anyone
>> have a sample of this kind of code?
>>
>> Many thanks!
>>[/color]
>
>
>.
>[/color]
Bernie Yaeger
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Mad Libs-style program problem?


Hi Alice,

You have your assignments backwards - gstrsetting = txtsetting.text not the
other way around.

Bernie

"Alice" <anonymous@discussions.microsoft.com> wrote in message
news:04fa01c3bb94$d239e7b0$a301280a@phx.gbl...[color=blue]
> Thanks for responding.
>
> Here is my code:
>
> Public Class frmStoryGenerator
> Inherits System.Windows.Forms.Form
>
>
> ' Declare variables for user input text boxes
>
> Dim gstrSetting As String
> Dim gstrActivity As String
> Dim gstrVillain As String
> Dim gstrPluralNoun1 As String
> Dim gstrPluralNoun2 As String
> Dim gstrAdj1 As String
> Dim gstrAdj2 As String
> Dim gstrAdj3 As String
> Dim gstrAnimal As String
> Dim gstrCountry As String
> Dim gstrVerbIng1 As String
> Dim gstrVerbIng2 As String
> Dim gstrTimeOfYear As String
>
> ' Generate story in a message box
>
> Private Sub btnStory_Click(ByVal sender As
> System.Object, ByVal e As System.EventArgs) Handles
> btnStory.Click
>
>
> txtSetting.Text = gstrSetting
> txtTimeOfYear.Text = gstrTimeOfYear
> txtActivity.Text = gstrActivity
> txtVillain.Text = gstrVillian
> txtPluralNoun1.Text = gstrPluralNoun1
> txtPluralNoun2.Text = gstrPluralNoun2
> txtAdj1.Text = gstrAdj1
> txtAdj2.Text = gstrAdj2
> txtAdj3.Text = gstrAdj3
> txtAnimal.Text = gstrAnimal
> txtCountry.Text = gstrCountry
> txtVerbIng1.Text = gstrVerbIng1
> txtVerbIng2.Text = gstrVerbIng2
>
> MessageBox.Show("Once, when I was in " &
> gstrSetting & " in " & gstrTimeOfYear _
> & ", I was out " & gstrActivity & " and came across a " &
> gstrAdj1 & " sight. Of course, I was alone " _
> & " at the time, so I had to face the danger alone. Though
> it was a " & gstrAdj2 & " situation, I dove right in." _
> & gstrVillain & " was trying to take over the world by " &
> gstrVerbIng1 & gstrPluralNoun1 & ". The scheme" _
> & " had to be stopped. But there were " & gstrAdj2 & " " &
> gstrAdj3 & " in the way, not to mention voracious" _
> & gstrPluralNoun2 & ". Still, it was all up to me to stop
> it. I was victorious by " & gstrVerbIng2 & " into a large"
> _
> & " lake full of " & gstrAnimal & " and wrestling them all
> while single-handedly convincing the local superhero of " _
> & gstrCountry & " to step in and help. We started to
> drive " & gstrVillian & " away. But just then, the
> superhero " _
> & " turned to wood, so it was all up to me. I stuffed the
> villian into a large gunnysack and launched him to the
> moon." _
> & "Believe me, it happened. It's true." _
> & " Really. The End.")
>
> End Sub
>
>
> End Class
>[color=green]
> >-----Original Message-----
> >Hi Alice,
> >
> >Sounds pretty simple - you just want to search and[/color]
> replace in a large[color=green]
> >string. Please show us your code - specifically the code[/color]
> that parses the[color=green]
> >long string - and I'm sure someone here can help.
> >
> >HTH,
> >
> >Bernie Yaeger
> >
> >"Alice" <anonymous@discussions.microsoft.com> wrote in[/color]
> message[color=green]
> >news:05dc01c3bb8c$96f8a900$a101280a@phx.gbl...[color=darkred]
> >> Hi -- I am trying to code a "mad libs" style program, in
> >> which the user puts in nouns, adjectives, etc., into[/color][/color]
> text[color=green][color=darkred]
> >> boxes. Then the user clicks on a button which opens a
> >> message box. Inside the message box is a story with[/color][/color]
> blanks[color=green][color=darkred]
> >> filled in by what the user entered into the text boxes.
> >>
> >> Only when my message box opens, it does not plug in the
> >> user's words.
> >>
> >> Can anyone tell me what I'm doing wrong, or does anyone
> >> have a sample of this kind of code?
> >>
> >> Many thanks!
> >>[/color]
> >
> >
> >.
> >[/color][/color]


RDI
Guest
 
Posts: n/a
#5: Nov 20 '05

re: Mad Libs-style program problem?


Why would you need to use replace?

Why not just build the text into the string in the first place.

This is a VERY basic version of what Alice was talking about:

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents tbxName As System.Windows.Forms.TextBox

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents Label2 As System.Windows.Forms.Label

Friend WithEvents tbxHome As System.Windows.Forms.TextBox

Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox

Friend WithEvents btnShow As System.Windows.Forms.Button

Friend WithEvents btnOK As System.Windows.Forms.Button

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.tbxName = New System.Windows.Forms.TextBox()

Me.Label1 = New System.Windows.Forms.Label()

Me.Label2 = New System.Windows.Forms.Label()

Me.tbxHome = New System.Windows.Forms.TextBox()

Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()

Me.btnShow = New System.Windows.Forms.Button()

Me.btnOK = New System.Windows.Forms.Button()

Me.SuspendLayout()

'

'tbxName

'

Me.tbxName.Location = New System.Drawing.Point(88, 24)

Me.tbxName.Name = "tbxName"

Me.tbxName.TabIndex = 0

Me.tbxName.Text = ""

'

'Label1

'

Me.Label1.Location = New System.Drawing.Point(16, 24)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(56, 23)

Me.Label1.TabIndex = 1

Me.Label1.Text = "Name"

Me.Label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft

'

'Label2

'

Me.Label2.Location = New System.Drawing.Point(16, 56)

Me.Label2.Name = "Label2"

Me.Label2.Size = New System.Drawing.Size(64, 23)

Me.Label2.TabIndex = 3

Me.Label2.Text = "HomeTown"

Me.Label2.TextAlign = System.Drawing.ContentAlignment.BottomLeft

'

'tbxHome

'

Me.tbxHome.Location = New System.Drawing.Point(88, 56)

Me.tbxHome.Name = "tbxHome"

Me.tbxHome.TabIndex = 2

Me.tbxHome.Text = ""

'

'RichTextBox1

'

Me.RichTextBox1.Location = New System.Drawing.Point(200, 24)

Me.RichTextBox1.Name = "RichTextBox1"

Me.RichTextBox1.Size = New System.Drawing.Size(208, 96)

Me.RichTextBox1.TabIndex = 4

Me.RichTextBox1.Text = ""

'

'btnShow

'

Me.btnShow.Location = New System.Drawing.Point(88, 96)

Me.btnShow.Name = "btnShow"

Me.btnShow.TabIndex = 5

Me.btnShow.Text = "Show"

'

'btnOK

'

Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK

Me.btnOK.Location = New System.Drawing.Point(168, 160)

Me.btnOK.Name = "btnOK"

Me.btnOK.TabIndex = 6

Me.btnOK.Text = "Ok"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(424, 221)

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnOK,
Me.btnShow, Me.RichTextBox1, Me.Label2, Me.tbxHome, Me.Label1, Me.tbxName})

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShow.Click

Me.RichTextBox1.Text = "My name is " & Me.tbxName.Text &
Microsoft.VisualBasic.ChrW(10) & "I was born in " & Me.tbxHome.Text

End Sub

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click

Dispose()

End Sub

End Class


--

RDI

(remove the exclamation from the email address)

"Bernie Yaeger" <berniey@cherwellinc.com> wrote in message
news:On2Qe45uDHA.1788@tk2msftngp13.phx.gbl...[color=blue]
> Hi Alice,
>
> You have your assignments backwards - gstrsetting = txtsetting.text not[/color]
the[color=blue]
> other way around.
>
> Bernie
>
> "Alice" <anonymous@discussions.microsoft.com> wrote in message
> news:04fa01c3bb94$d239e7b0$a301280a@phx.gbl...[color=green]
> > Thanks for responding.
> >
> > Here is my code:
> >
> > Public Class frmStoryGenerator
> > Inherits System.Windows.Forms.Form
> >
> >
> > ' Declare variables for user input text boxes
> >
> > Dim gstrSetting As String
> > Dim gstrActivity As String
> > Dim gstrVillain As String
> > Dim gstrPluralNoun1 As String
> > Dim gstrPluralNoun2 As String
> > Dim gstrAdj1 As String
> > Dim gstrAdj2 As String
> > Dim gstrAdj3 As String
> > Dim gstrAnimal As String
> > Dim gstrCountry As String
> > Dim gstrVerbIng1 As String
> > Dim gstrVerbIng2 As String
> > Dim gstrTimeOfYear As String
> >
> > ' Generate story in a message box
> >
> > Private Sub btnStory_Click(ByVal sender As
> > System.Object, ByVal e As System.EventArgs) Handles
> > btnStory.Click
> >
> >
> > txtSetting.Text = gstrSetting
> > txtTimeOfYear.Text = gstrTimeOfYear
> > txtActivity.Text = gstrActivity
> > txtVillain.Text = gstrVillian
> > txtPluralNoun1.Text = gstrPluralNoun1
> > txtPluralNoun2.Text = gstrPluralNoun2
> > txtAdj1.Text = gstrAdj1
> > txtAdj2.Text = gstrAdj2
> > txtAdj3.Text = gstrAdj3
> > txtAnimal.Text = gstrAnimal
> > txtCountry.Text = gstrCountry
> > txtVerbIng1.Text = gstrVerbIng1
> > txtVerbIng2.Text = gstrVerbIng2
> >
> > MessageBox.Show("Once, when I was in " &
> > gstrSetting & " in " & gstrTimeOfYear _
> > & ", I was out " & gstrActivity & " and came across a " &
> > gstrAdj1 & " sight. Of course, I was alone " _
> > & " at the time, so I had to face the danger alone. Though
> > it was a " & gstrAdj2 & " situation, I dove right in." _
> > & gstrVillain & " was trying to take over the world by " &
> > gstrVerbIng1 & gstrPluralNoun1 & ". The scheme" _
> > & " had to be stopped. But there were " & gstrAdj2 & " " &
> > gstrAdj3 & " in the way, not to mention voracious" _
> > & gstrPluralNoun2 & ". Still, it was all up to me to stop
> > it. I was victorious by " & gstrVerbIng2 & " into a large"
> > _
> > & " lake full of " & gstrAnimal & " and wrestling them all
> > while single-handedly convincing the local superhero of " _
> > & gstrCountry & " to step in and help. We started to
> > drive " & gstrVillian & " away. But just then, the
> > superhero " _
> > & " turned to wood, so it was all up to me. I stuffed the
> > villian into a large gunnysack and launched him to the
> > moon." _
> > & "Believe me, it happened. It's true." _
> > & " Really. The End.")
> >
> > End Sub
> >
> >
> > End Class
> >[color=darkred]
> > >-----Original Message-----
> > >Hi Alice,
> > >
> > >Sounds pretty simple - you just want to search and[/color]
> > replace in a large[color=darkred]
> > >string. Please show us your code - specifically the code[/color]
> > that parses the[color=darkred]
> > >long string - and I'm sure someone here can help.
> > >
> > >HTH,
> > >
> > >Bernie Yaeger
> > >
> > >"Alice" <anonymous@discussions.microsoft.com> wrote in[/color]
> > message[color=darkred]
> > >news:05dc01c3bb8c$96f8a900$a101280a@phx.gbl...
> > >> Hi -- I am trying to code a "mad libs" style program, in
> > >> which the user puts in nouns, adjectives, etc., into[/color]
> > text[color=darkred]
> > >> boxes. Then the user clicks on a button which opens a
> > >> message box. Inside the message box is a story with[/color]
> > blanks[color=darkred]
> > >> filled in by what the user entered into the text boxes.
> > >>
> > >> Only when my message box opens, it does not plug in the
> > >> user's words.
> > >>
> > >> Can anyone tell me what I'm doing wrong, or does anyone
> > >> have a sample of this kind of code?
> > >>
> > >> Many thanks!
> > >>
> > >
> > >
> > >.
> > >[/color][/color]
>
>[/color]


Alice
Guest
 
Posts: n/a
#6: Nov 20 '05

re: Mad Libs-style program problem?


Bernie,

You absolutely rock! I can't believe I didn't see that!
Thank you so much! My program works perfectly now.

RDI,
Thank you for showing me an alternative way I could do
this kind of program!

Many thanks,
Alice

[color=blue]
>-----Original Message-----
>Hi Alice,
>
>You have your assignments backwards - gstrsetting =[/color]
txtsetting.text not the[color=blue]
>other way around.
>
>Bernie
>
>"Alice" <anonymous@discussions.microsoft.com> wrote in[/color]
message[color=blue]
>news:04fa01c3bb94$d239e7b0$a301280a@phx.gbl...[color=green]
>> Thanks for responding.
>>
>> Here is my code:
>>
>> Public Class frmStoryGenerator
>> Inherits System.Windows.Forms.Form
>>
>>
>> ' Declare variables for user input text boxes
>>
>> Dim gstrSetting As String
>> Dim gstrActivity As String
>> Dim gstrVillain As String
>> Dim gstrPluralNoun1 As String
>> Dim gstrPluralNoun2 As String
>> Dim gstrAdj1 As String
>> Dim gstrAdj2 As String
>> Dim gstrAdj3 As String
>> Dim gstrAnimal As String
>> Dim gstrCountry As String
>> Dim gstrVerbIng1 As String
>> Dim gstrVerbIng2 As String
>> Dim gstrTimeOfYear As String
>>
>> ' Generate story in a message box
>>
>> Private Sub btnStory_Click(ByVal sender As
>> System.Object, ByVal e As System.EventArgs) Handles
>> btnStory.Click
>>
>>
>> txtSetting.Text = gstrSetting
>> txtTimeOfYear.Text = gstrTimeOfYear
>> txtActivity.Text = gstrActivity
>> txtVillain.Text = gstrVillian
>> txtPluralNoun1.Text = gstrPluralNoun1
>> txtPluralNoun2.Text = gstrPluralNoun2
>> txtAdj1.Text = gstrAdj1
>> txtAdj2.Text = gstrAdj2
>> txtAdj3.Text = gstrAdj3
>> txtAnimal.Text = gstrAnimal
>> txtCountry.Text = gstrCountry
>> txtVerbIng1.Text = gstrVerbIng1
>> txtVerbIng2.Text = gstrVerbIng2
>>
>> MessageBox.Show("Once, when I was in " &
>> gstrSetting & " in " & gstrTimeOfYear _
>> & ", I was out " & gstrActivity & " and came across a "[/color][/color]
&[color=blue][color=green]
>> gstrAdj1 & " sight. Of course, I was alone " _
>> & " at the time, so I had to face the danger alone.[/color][/color]
Though[color=blue][color=green]
>> it was a " & gstrAdj2 & " situation, I dove right in." _
>> & gstrVillain & " was trying to take over the world[/color][/color]
by " &[color=blue][color=green]
>> gstrVerbIng1 & gstrPluralNoun1 & ". The scheme" _
>> & " had to be stopped. But there were " & gstrAdj2[/color][/color]
& " " &[color=blue][color=green]
>> gstrAdj3 & " in the way, not to mention voracious" _
>> & gstrPluralNoun2 & ". Still, it was all up to me to[/color][/color]
stop[color=blue][color=green]
>> it. I was victorious by " & gstrVerbIng2 & " into a[/color][/color]
large"[color=blue][color=green]
>> _
>> & " lake full of " & gstrAnimal & " and wrestling them[/color][/color]
all[color=blue][color=green]
>> while single-handedly convincing the local superhero[/color][/color]
of " _[color=blue][color=green]
>> & gstrCountry & " to step in and help. We started to
>> drive " & gstrVillian & " away. But just then, the
>> superhero " _
>> & " turned to wood, so it was all up to me. I stuffed[/color][/color]
the[color=blue][color=green]
>> villian into a large gunnysack and launched him to the
>> moon." _
>> & "Believe me, it happened. It's true." _
>> & " Really. The End.")
>>
>> End Sub
>>
>>
>> End Class
>>[color=darkred]
>> >-----Original Message-----
>> >Hi Alice,
>> >
>> >Sounds pretty simple - you just want to search and[/color]
>> replace in a large[color=darkred]
>> >string. Please show us your code - specifically the[/color][/color][/color]
code[color=blue][color=green]
>> that parses the[color=darkred]
>> >long string - and I'm sure someone here can help.
>> >
>> >HTH,
>> >
>> >Bernie Yaeger
>> >
>> >"Alice" <anonymous@discussions.microsoft.com> wrote in[/color]
>> message[color=darkred]
>> >news:05dc01c3bb8c$96f8a900$a101280a@phx.gbl...
>> >> Hi -- I am trying to code a "mad libs" style[/color][/color][/color]
program, in[color=blue][color=green][color=darkred]
>> >> which the user puts in nouns, adjectives, etc., into[/color]
>> text[color=darkred]
>> >> boxes. Then the user clicks on a button which opens a
>> >> message box. Inside the message box is a story with[/color]
>> blanks[color=darkred]
>> >> filled in by what the user entered into the text[/color][/color][/color]
boxes.[color=blue][color=green][color=darkred]
>> >>
>> >> Only when my message box opens, it does not plug in[/color][/color][/color]
the[color=blue][color=green][color=darkred]
>> >> user's words.
>> >>
>> >> Can anyone tell me what I'm doing wrong, or does[/color][/color][/color]
anyone[color=blue][color=green][color=darkred]
>> >> have a sample of this kind of code?
>> >>
>> >> Many thanks!
>> >>
>> >
>> >
>> >.
>> >[/color][/color]
>
>
>.
>[/color]
Bernie Yaeger
Guest
 
Posts: n/a
#7: Nov 20 '05

re: Mad Libs-style program problem?


Hi Alice,

Your very welcome.

Bernie
"Alice" <anonymous@discussions.microsoft.com> wrote in message
news:021e01c3bc44$b64c5640$a101280a@phx.gbl...[color=blue]
> Bernie,
>
> You absolutely rock! I can't believe I didn't see that!
> Thank you so much! My program works perfectly now.
>
> RDI,
> Thank you for showing me an alternative way I could do
> this kind of program!
>
> Many thanks,
> Alice
>
>[color=green]
> >-----Original Message-----
> >Hi Alice,
> >
> >You have your assignments backwards - gstrsetting =[/color]
> txtsetting.text not the[color=green]
> >other way around.
> >
> >Bernie
> >
> >"Alice" <anonymous@discussions.microsoft.com> wrote in[/color]
> message[color=green]
> >news:04fa01c3bb94$d239e7b0$a301280a@phx.gbl...[color=darkred]
> >> Thanks for responding.
> >>
> >> Here is my code:
> >>
> >> Public Class frmStoryGenerator
> >> Inherits System.Windows.Forms.Form
> >>
> >>
> >> ' Declare variables for user input text boxes
> >>
> >> Dim gstrSetting As String
> >> Dim gstrActivity As String
> >> Dim gstrVillain As String
> >> Dim gstrPluralNoun1 As String
> >> Dim gstrPluralNoun2 As String
> >> Dim gstrAdj1 As String
> >> Dim gstrAdj2 As String
> >> Dim gstrAdj3 As String
> >> Dim gstrAnimal As String
> >> Dim gstrCountry As String
> >> Dim gstrVerbIng1 As String
> >> Dim gstrVerbIng2 As String
> >> Dim gstrTimeOfYear As String
> >>
> >> ' Generate story in a message box
> >>
> >> Private Sub btnStory_Click(ByVal sender As
> >> System.Object, ByVal e As System.EventArgs) Handles
> >> btnStory.Click
> >>
> >>
> >> txtSetting.Text = gstrSetting
> >> txtTimeOfYear.Text = gstrTimeOfYear
> >> txtActivity.Text = gstrActivity
> >> txtVillain.Text = gstrVillian
> >> txtPluralNoun1.Text = gstrPluralNoun1
> >> txtPluralNoun2.Text = gstrPluralNoun2
> >> txtAdj1.Text = gstrAdj1
> >> txtAdj2.Text = gstrAdj2
> >> txtAdj3.Text = gstrAdj3
> >> txtAnimal.Text = gstrAnimal
> >> txtCountry.Text = gstrCountry
> >> txtVerbIng1.Text = gstrVerbIng1
> >> txtVerbIng2.Text = gstrVerbIng2
> >>
> >> MessageBox.Show("Once, when I was in " &
> >> gstrSetting & " in " & gstrTimeOfYear _
> >> & ", I was out " & gstrActivity & " and came across a "[/color][/color]
> &[color=green][color=darkred]
> >> gstrAdj1 & " sight. Of course, I was alone " _
> >> & " at the time, so I had to face the danger alone.[/color][/color]
> Though[color=green][color=darkred]
> >> it was a " & gstrAdj2 & " situation, I dove right in." _
> >> & gstrVillain & " was trying to take over the world[/color][/color]
> by " &[color=green][color=darkred]
> >> gstrVerbIng1 & gstrPluralNoun1 & ". The scheme" _
> >> & " had to be stopped. But there were " & gstrAdj2[/color][/color]
> & " " &[color=green][color=darkred]
> >> gstrAdj3 & " in the way, not to mention voracious" _
> >> & gstrPluralNoun2 & ". Still, it was all up to me to[/color][/color]
> stop[color=green][color=darkred]
> >> it. I was victorious by " & gstrVerbIng2 & " into a[/color][/color]
> large"[color=green][color=darkred]
> >> _
> >> & " lake full of " & gstrAnimal & " and wrestling them[/color][/color]
> all[color=green][color=darkred]
> >> while single-handedly convincing the local superhero[/color][/color]
> of " _[color=green][color=darkred]
> >> & gstrCountry & " to step in and help. We started to
> >> drive " & gstrVillian & " away. But just then, the
> >> superhero " _
> >> & " turned to wood, so it was all up to me. I stuffed[/color][/color]
> the[color=green][color=darkred]
> >> villian into a large gunnysack and launched him to the
> >> moon." _
> >> & "Believe me, it happened. It's true." _
> >> & " Really. The End.")
> >>
> >> End Sub
> >>
> >>
> >> End Class
> >>
> >> >-----Original Message-----
> >> >Hi Alice,
> >> >
> >> >Sounds pretty simple - you just want to search and
> >> replace in a large
> >> >string. Please show us your code - specifically the[/color][/color]
> code[color=green][color=darkred]
> >> that parses the
> >> >long string - and I'm sure someone here can help.
> >> >
> >> >HTH,
> >> >
> >> >Bernie Yaeger
> >> >
> >> >"Alice" <anonymous@discussions.microsoft.com> wrote in
> >> message
> >> >news:05dc01c3bb8c$96f8a900$a101280a@phx.gbl...
> >> >> Hi -- I am trying to code a "mad libs" style[/color][/color]
> program, in[color=green][color=darkred]
> >> >> which the user puts in nouns, adjectives, etc., into
> >> text
> >> >> boxes. Then the user clicks on a button which opens a
> >> >> message box. Inside the message box is a story with
> >> blanks
> >> >> filled in by what the user entered into the text[/color][/color]
> boxes.[color=green][color=darkred]
> >> >>
> >> >> Only when my message box opens, it does not plug in[/color][/color]
> the[color=green][color=darkred]
> >> >> user's words.
> >> >>
> >> >> Can anyone tell me what I'm doing wrong, or does[/color][/color]
> anyone[color=green][color=darkred]
> >> >> have a sample of this kind of code?
> >> >>
> >> >> Many thanks!
> >> >>
> >> >
> >> >
> >> >.
> >> >[/color]
> >
> >
> >.
> >[/color][/color]


Closed Thread


Similar Visual Basic .NET bytes