Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Foreign Languages > German Forum
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Random Antworten

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-13-2012, 12:38 PM
Senior Member
 
Join Date: Dec 2011
Posts: 147
Default Random Antworten

Hi,
Ist es möglich wenn ich eine frage in eine textbox schreibe, random antworten zu generieren?

Sprich ich habe 4 antworten festgelegt und bekomme eine von den antworten (random)

Mein code bisher -->

If edittext1.Text.Contains("teste es") Then
Dim k As int
Dim i As Int
Dim answers() As String
answers(0)="Hallöchen halli hallo."
answers(1)="test"
answers(2)="test2"
answers(3)="test3"

For i = 0 To 3
i = i+1

Next

For i = 0 To 3
k = Rnd(i, 4)

answers(i) = answers(k)
Next

label1.Text =answers(k)

Bekomme eine arryindexoutofboundsexception

Kann mir jemand bisschen weiterhelfen?

Last edited by mcmanu : 01-13-2012 at 01:13 PM.
Reply With Quote
  #2 (permalink)  
Old 01-13-2012, 01:40 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 1,057
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Hallo mcmanu,

die Exception bekommst Du, weil das StringArray für die Antworten nicht korrekt definiert ist.
Code:
Dim answers(4As String
Insgesamt reichen folgende Anweisungen:
Code:
Dim answers(4As String
answers(
0)="Hall�chen halli hallo."
answers(
1)="test"
answers(
2)="test2"
answers(
3)="test3"
Label1.Text = answers(
Rnd(04))

Gruß
specci48
Reply With Quote
  #3 (permalink)  
Old 01-13-2012, 01:49 PM
Senior Member
 
Join Date: Dec 2011
Posts: 147
Default

Quote:
Originally Posted by specci48 View Post
Hallo mcmanu,

die Exception bekommst Du, weil das StringArray für die Antworten nicht korrekt definiert ist.
Code:
Dim answers(4As String
Insgesamt reichen folgende Anweisungen:
Code:
Dim answers(4As String
answers(
0)="Hall�chen halli hallo."
answers(
1)="test"
answers(
2)="test2"
answers(
3)="test3"
Label1.Text = answers(
Rnd(04))

Gruß
specci48

Danke specci48
Ja stimmt des hatte ich nicht beachtet
Danke dir für die schnelle antwort, es funktioniert super dachte nicht das es so easy ist xD
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace random Gigatron Basic4android Updates and Questions 1 10-12-2011 09:03 PM
CSDB Random release Funnybones Basic4android Share Your Creations 2 08-22-2011 02:43 PM
Seeding a random # generator nfordbscndrd Basic4android Updates and Questions 6 07-03-2011 06:49 AM
The same random numbers LineCutter Questions (Windows Mobile) 4 10-16-2008 05:05 PM
how to random shuffle an array? Stellaferox Questions (Windows Mobile) 9 07-01-2007 10:48 AM


All times are GMT. The time now is 06:38 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0