Android Question Random Number

Antonio Costa

Member
Licensed User
hello all, I was just looking for a solution for a random numbers, I tried to enter text on 4 buttons, where one of them must have an exact result, when I click on the result example buttonA the number should change passing the result on a other button, but the exact result always remains on buttonA, except if I do not click on a buttonB you go error,so when i got error it change both num1 + num2 but also the result on another button (exp: buttonD), I think I have combined a brothel in the code, I would be grateful if you would help me



B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim timer1 As Timer
    Dim stu As StringUtils

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private introLabel As Label
    Private mathLabel As Label
    Private okButton As Button
'    Private resultField As EditText
    Private titleImage As ImageView
    Dim myImage As Bitmap
    
    Dim testLevel As Int
    Dim resultInt As Int
    Private progressTest As ProgressBar
    Private errorsLabel As Label
    Private questionNumLabel As Label
    
    Dim indexMax As Int
    Dim errorsTotal As Int
    Private backgroundImage As ImageView
    Private timeLabel As Label
    Dim timePassed As Int
    
    Dim stu As StringUtils
    Dim minutes As Int
    Private Panel1 As Panel
    Private panelTitleLabel As Label
    Private panelLabel As Label
    Private panelButton As Button
    
    Dim dayTodayString As String
    Dim monthTodayString As String
    Dim monthString As String
    Dim yearTodayString As String
    
    
    Dim ListResult(100) As String
    
    Private listButton As Button
    Private dataLabel As Label
    Private infoButton As Button
    Private buttonA As Button
    Private buttonB As Button
    Private buttonC As Button
    Private buttonD As Button
    
    
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Livello1")
    
    FindDate
    CalculateMonth
    dataLabel.Text = dayTodayString & " " & monthString & " " &  yearTodayString
    
    
    Panel1.Visible = False
    
    timer1.Initialize("timer1", 1000) '1000 = 1 secondo
    ' timeLabel.Text = "Tempo: 0"
    timeLabel.TextColor = Colors.Black
    timePassed = 0 'inizializzo variabilke secondi
    minutes = 0 'inizializzo variabile minuti
    timeLabel.Text = "Tempo: 00m : 00s"
    
    errorsTotal = 0
    errorsLabel.Text = "Errori: " & errorsTotal
    
    progressTest.Progress = 0
    indexMax = 15 'avanzamento della progressbarr dei livelli , aumentare di 1 per ogni livello aggiunto
    SetMaxProgressBar 'assegno il valore alla progressbar
    
    
    'colore sfondo finestra di testo
'    resultField.Color = Colors.White
'    resultField.TextColor = Colors.Black
'    resultField.Hint = "Scrivi qui la tua Risposta"
'    resultField.HintColor = Colors.Gray
    
    introLabel.TextColor = Colors.Red
    mathLabel.TextColor = Colors.Black
    errorsLabel.TextColor = Colors.Blue
    questionNumLabel.TextColor = Colors.Blue
    
    Dim gd As GradientDrawable
    gd.Initialize("LEFT_RIGHT" , Array As Int(Colors.RGB(195,255,116), Colors.RGB(50,231,0)))
    gd.CornerRadius = 23dip
    SetProgressDrawable(progressTest, gd)
    
    
    testLevel = 0
    questionNumLabel.Text = "Domanda N°: " & testLevel
    
    
    'okButton.Text = "OK!"
    SetButtonTextSize(okButton, "OK!")
    SetButtonTextSize(panelButton, "OK!")
    
    
    
    'carico immagine titolo
    titleImage.Bitmap = LoadBitmap(File.DirAssets, "title.png")
    'carico immagine background
    backgroundImage.Bitmap = LoadBitmap(File.DirAssets, "mathPaper.png")
    
    myImage.Initialize(File.DirAssets, "List.png")
    listButton.SetBackgroundImage(myImage)
    
    
    
    Activity.Title = "Math Test"
    
    
    'introLabel.Text = "Clicca Ok per Iniziare"
    SetLabelSize(introLabel, "Clicca Ok per Iniziare")
    
    'carico immagine bottone
    myImage.Initialize(File.DirAssets, "button-blue.png")
    okButton.SetBackgroundImage(myImage)
    panelButton.SetBackgroundImage(myImage)
    
    'carico immagine bottone
    myImage.Initialize(File.DirAssets, "infoButton.png")
    infoButton.SetBackgroundImage(myImage)
    
    
    myImage.Initialize(File.DirAssets, "panelB.png")
    Panel1.SetBackgroundImage(myImage)
    
    panelTitleLabel.TextColor = Colors.Black
    panelLabel.TextColor = Colors.Red
    
    
    buttonA.TextColor = Colors.White
    buttonB.TextColor = Colors.White
    buttonC.TextColor = Colors.White
    buttonD.TextColor = Colors.White
    buttonA.Color = Colors.Blue
    buttonB.Color = Colors.Blue
    buttonC.Color = Colors.Blue
    buttonD.Color = Colors.Blue
    
    
    'lancio il primo calcolo
    'CreateCalculation
    
    
End Sub

Sub Activity_Resume

End Sub

Sub SetProgressDrawable(p As ProgressBar, drawable As Object)
    Dim r As Reflector
    Dim clipDrawable As Object
    clipDrawable = r.CreateObject2("android.graphics.drawable.ClipDrawable", _
      Array As Object(drawable, Gravity.LEFT, 1), _
      Array As String("android.graphics.drawable.Drawable", "java.lang.int", "java.lang.int"))
    r.Target = p
    r.Target = r.RunMethod("getProgressDrawable") 'Gets the layerDrawable
    r.RunMethod4("setDrawableByLayerId", _
      Array As Object(r.GetStaticField("android.R$id", "progress"), clipDrawable), _
      Array As String("java.lang.int", "android.graphics.drawable.Drawable"))
End Sub

    'con questo sub imposto il massimo della progressbar
Sub SetMaxProgressBar
    Dim rlfBar As Reflector
    rlfBar.Target = progressTest
    rlfBar.RunMethod2("setMax",indexMax, "java.lang.int")
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub timer1_Tick
    
    Dim minutesString As String
    Dim secondsString As String
    
    
    timePassed = timePassed + 1
    
    If timePassed = 60 Then
        minutes = minutes +1
        timePassed = 0
    End If
    'modalita con Or per ottenere 2 zeri nel timer
    If minutes = 0 Or minutes = 1 Or minutes = 2 Or minutes = 3 Or minutes = 4 Or minutes = 5 Or minutes = 6 Or minutes = 7 Or minutes = 8 Or minutes = 9 Then
        minutesString = "0" & minutes
    Else
        minutesString = minutes
    End If
    
    'modalità con <
    If timePassed < 10 Then
        secondsString = "0" & timePassed
    Else
        secondsString = timePassed
    End If
    
    
    timeLabel.Text = "Tempo: " & minutesString & "m : " & secondsString & "s"
    
    
          
End Sub

Sub CalculateMonth
    
    If monthTodayString = 1 Then
        monthString = "Gennaio"
    Else If monthTodayString = 2 Then
        monthString = "Febbraio"
    Else If monthTodayString = 3 Then
        monthString = "Marzo"
    Else If monthTodayString = 4 Then
        monthString = "Aprile"
    Else If monthTodayString = 5 Then
        monthString = "Maggio"
    Else If monthTodayString = 6 Then
        monthString = "Giugno"
    Else If monthTodayString = 7 Then
        monthString = "Luglio"
    Else If monthTodayString = 8 Then
        monthString = "Agosto"
    Else If monthTodayString = 9 Then
        monthString = "Settembre"
    Else If monthTodayString = 10 Then
        monthString = "Ottobre"
    Else If monthTodayString = 11 Then
        monthString = "Novembre"
    Else If monthTodayString = 12 Then
        monthString = "Dicembre"
        
    End If
    
End Sub

Sub CreateCalculation
    
    Dim num1 As Int
    Dim num2 As Int
    Dim num3 As Int
    Dim num4 As Int
    Dim num5 As Int
    Dim num6 As Int
    
    If testLevel = 1 Then
'        okButton.Visible = False   fa scomparire il bottone ok dopo la partenza
        
        num1 = Rnd(1,6)  'da un numero random tra 1 e 100
        num2 = Rnd(1,6)
        
        

        
        
        'mathLabel.Text = num1 & " + " & num2
        SetLabelSize(mathLabel, num1 & " + " & num2)
        resultInt = num1 + num2
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonA, resultInt)
        buttonA.Text = resultInt
        
        
    Else if testLevel = 2    Then
        
        buttonA.Text = Rnd(1,101)
        
        
        num1 = Rnd(1,11)  'da un numero random tra 1 e 100
        num2 = Rnd(1,11)
        num3 = Rnd(1,11)
        
        

        
        'mathLabel.Text = num1 & " + " & num2 & " - " & num3
        SetLabelSize(mathLabel, num1 & " + " & num2)
        resultInt = num1 + num2
        
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonB, resultInt)
        buttonB.Text = resultInt
        
    Else if testLevel = 3    Then
        
        
        num1 = Rnd(1,16)  'da un numero random tra 1 e 9
        num2 = Rnd(1,6)
        num3 = Rnd(10,101)  'da un numero random tra 1 e 100
        
        'mathLabel.Text = "(" & num1 & " x " & num2 & ") - " & num3
        SetLabelSize(mathLabel, num1 & " + " & num2)
        resultInt = num1 + num2
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonC, resultInt)
        buttonC.Text = resultInt
        
    Else if testLevel = 4    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(1,21)
        num3 = Rnd(10,101)  'da un numero random tra 1 e 100
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") x " & num1 & ") +  " & num3
        SetLabelSize(mathLabel, num1 & " + " & num2)
        resultInt = num1 + num2
        
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonB, resultInt)
        buttonB.Text = resultInt
        
    Else if testLevel = 5    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(1,71)
        num3 = Rnd(1,10)
        num4 = Rnd(10,101)  'da un numero random tra 1 e 100
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) + " & num4
        SetLabelSize(mathLabel, num1 & " + " & num2)
        resultInt = num1 + num2
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonD, resultInt)
        buttonD.Text = resultInt
        
    Else if testLevel = 6    Then
        
        
        num1 = Rnd(1,31)  'da un numero random tra 1 e 9
        num2 = Rnd(1,91)
        num3 = Rnd(1,10)
        num4 = Rnd(1,10)
        num5 = Rnd(1,31)  'da un numero random tra 1 e 30
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5
        SetLabelSize(mathLabel, num1 & " + " & num2)
        resultInt = num1 + num2
        
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonB, resultInt)
        buttonB.Text = resultInt
        
    Else if testLevel = 7    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(1,21)
        num3 = Rnd(1,101)
        num4 = Rnd(1,10)
        num5 = Rnd(1,10)
        num6 = Rnd(9,10)  'da un numero random tra 1 e 9
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5 & " / " & num6
        SetLabelSize(mathLabel, num1 & " + " & num2 & " +" & num3)
        resultInt = num1 + num2 + num3
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonC, resultInt)
        buttonC.Text = resultInt
                

        
    Else if testLevel = 8    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(10,11)  'da un numero random tra 9 e 10
        num3 = Rnd(1,10)  'da un numero random tra 1 e 9
        num4 = Rnd(10,21) 'da un numero random tra 10 e 20
        num5 = Rnd(1,10)  'da un numero random tra 1 e 9
        num6 = Rnd(10,51) 'da un numero random tra 10 e 50
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5 & " / " & num6
        SetLabelSize(mathLabel, num1 & " + " & num2 & " +" & num3)
        resultInt = num1 + num2 + num3
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonA, resultInt)
        buttonA.Text = resultInt
        
    Else if testLevel = 9    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(10,11)  'da un numero random tra 9 e 10
        num3 = Rnd(1,10)  'da un numero random tra 1 e 9
        num4 = Rnd(10,21) 'da un numero random tra 10 e 20
        num5 = Rnd(1,10)  'da un numero random tra 1 e 9
        num6 = Rnd(10,51) 'da un numero random tra 10 e 50
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5 & " / " & num6
        SetLabelSize(mathLabel, num1 & " + " & num2 & " +" & num3)
        resultInt = num1 + num2 + num3
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonD, resultInt)
        buttonD.Text = resultInt
        
    Else if testLevel = 10    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(10,11)  'da un numero random tra 9 e 10
        num3 = Rnd(1,10)  'da un numero random tra 1 e 9
        num4 = Rnd(10,21) 'da un numero random tra 10 e 20
        num5 = Rnd(1,10)  'da un numero random tra 1 e 9
        num6 = Rnd(10,51) 'da un numero random tra 10 e 50
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5 & " / " & num6
        SetLabelSize(mathLabel, num1 & " + " & num2 & " +" & num3)
        resultInt = num1 + num2 + num3
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonC, resultInt)
        
    Else if testLevel = 11    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(10,11)  'da un numero random tra 9 e 10
        num3 = Rnd(1,10)  'da un numero random tra 1 e 9
        num4 = Rnd(10,21) 'da un numero random tra 10 e 20
        num5 = Rnd(1,10)  'da un numero random tra 1 e 9
        num6 = Rnd(10,51) 'da un numero random tra 10 e 50
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5 & " / " & num6
        SetLabelSize(mathLabel, num1 & " + " & num2 & " +" & num3)
        resultInt = num1 + num2 + num3
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonD, resultInt)
        
    Else if testLevel = 12    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(10,11)  'da un numero random tra 9 e 10
        num3 = Rnd(1,10)  'da un numero random tra 1 e 9
        num4 = Rnd(10,21) 'da un numero random tra 10 e 20
        num5 = Rnd(1,10)  'da un numero random tra 1 e 9
        num6 = Rnd(10,51) 'da un numero random tra 10 e 50
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5 & " / " & num6
        SetLabelSize(mathLabel, num1 & " + " & num2 & " +" & num3)
        resultInt = num1 + num2 + num3
        
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonB, resultInt)
        
    Else if testLevel = 13    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(10,11)  'da un numero random tra 9 e 10
        num3 = Rnd(1,10)  'da un numero random tra 1 e 9
        num4 = Rnd(10,21) 'da un numero random tra 10 e 20
        num5 = Rnd(1,10)  'da un numero random tra 1 e 9
        num6 = Rnd(10,51) 'da un numero random tra 10 e 50
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5 & " / " & num6
        SetLabelSize(mathLabel, num1 & " + " & num2 & " +" & num3)
        resultInt = num1 + num2 + num3
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonD, resultInt)
        
    Else if testLevel = 14    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(10,11)  'da un numero random tra 9 e 10
        num3 = Rnd(1,10)  'da un numero random tra 1 e 9
        num4 = Rnd(10,21) 'da un numero random tra 10 e 20
        num5 = Rnd(1,10)  'da un numero random tra 1 e 9
        num6 = Rnd(10,51) 'da un numero random tra 10 e 50
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5 & " / " & num6
        SetLabelSize(mathLabel, num1 & " + " & num2 & " +" & num3)
        resultInt = num1 + num2 + num3
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonD, Rnd(1,101))
        SetButtonTextSize(buttonA, resultInt)
        
    Else if testLevel = 15    Then
        
        
        num1 = Rnd(1,10)  'da un numero random tra 1 e 9
        num2 = Rnd(10,11)  'da un numero random tra 9 e 10
        num3 = Rnd(1,10)  'da un numero random tra 1 e 9
        num4 = Rnd(10,21) 'da un numero random tra 10 e 20
        num5 = Rnd(1,10)  'da un numero random tra 1 e 9
        num6 = Rnd(10,51) 'da un numero random tra 10 e 50
        
        'mathLabel.Text = "((" & num1 & " x " & num2 & ") - (" & num1 & " x " & num3 & ")) - " & num4 & " + " & num5 & " / " & num6
        SetLabelSize(mathLabel, num1 & " + " & num2 & " +" & num3)
        resultInt = num1 + num2 + num3
        
        SetButtonTextSize(buttonB, Rnd(1,101))
        SetButtonTextSize(buttonC, Rnd(1,101))
        SetButtonTextSize(buttonA, Rnd(1,101))
        SetButtonTextSize(buttonD, resultInt)
        
    End If
    
    Log("Risultato:" & resultInt)
End Sub

Sub okButton_Click
'   
Dim minuteString As String
Dim secondString As String
Dim errorString As String
    
    If testLevel = 0 Then
        testLevel = 1
        questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
        CreateCalculation
        'introLabel.Text = "Scrivi qui il risultato"
        SetLabelSize(introLabel, "Schegli il risultato esatto")
        timer1.Enabled = True
        SetButtonTextSize(okButton, "OK!")
        okButton.Visible = False  'disattivo il bottone ok dopo l'avvio del tempo
        
    Else
            
        If resultInt  = resultInt Then
            'pulisco la edittext
'            resultField.Text = ""
            ToastMessageShow("Risposta Giusta!",True)
            testLevel = testLevel + 1
            questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
            progressTest.Progress = progressTest.Progress + 1 'aumenta la progressbar ad ogni livello
            
            If testLevel < (indexMax+1) Then
                CreateCalculation
                
        
                
                If minutes = 1 Then
                    minuteString = "minuto"
                Else
                    minuteString = "minuti"
                End If
                
                If timePassed = 1 Then
                    secondString = "secondo"
                Else
                    secondString = "secondi"
                End If
                
                If errorsTotal = 1 Then
                    errorString = "Errore"
                Else
                    errorString = "Errori"
                End If
                
                mathLabel.Text = ""
'                resultField.Text = ""
                'okButton.Text = "Nuovo Livello"
                SetButtonTextSize(okButton, "Nuovo Livello!")
                questionNumLabel.Text = "Domanda N°: " 'livello nella label
                
                
                'Msgbox("Il test è terminato, hai risposto ad un totale di " & indexMax & " domande , con un totale di " & errorsTotal & " " & errorString & " , in " & minutes & " " & minuteString & " e " & timePassed & " " & secondString & ".", "Complimenti!!")
                
                
                If errorsTotal = 0 Then
                    'imposto i valori nel panel1
                    SetLabelSize(panelTitleLabel, "Complimenti!")
                    SetLabelSize(panelLabel, "Il test è terminato, hai risposto ad un totale di " & indexMax & " domande senza nessun errore in " & minutes & " " & minuteString & " e " & timePassed & " " & secondString & ". Sei un Drago della Matematica!")
                    
                    
                Else If errorsTotal < 3 Then
                    'imposto i valori nel panel1
                    SetLabelSize(panelTitleLabel, "Ben Fatto!")
                    SetLabelSize(panelLabel, "Il test è terminato, hai risposto ad un totale di " & indexMax & " domande , con un totale di " & errorsTotal & " " & errorString & " , in " & minutes & " " & minuteString & " e " & timePassed & " " & secondString & ". Puoi Fare di Meglio")
                    
                Else
                    'imposto i valori nel panel1
                    SetLabelSize(panelTitleLabel, "Test Fallito")
                    SetLabelSize(panelLabel, "Il test è terminato, hai risposto ad un totale di " & indexMax & " domande , con un totale di " & errorsTotal & " " & errorString & " , in " & minutes & " " & minuteString & " e " & timePassed & " " & secondString & ". Devi Studiare di Più :P")
                    
                End If
                
                
                RegisterResults(minutes,timePassed,errorsTotal)
            
                
                
                
                
                Panel1.Visible = True
                
                
                timer1.Enabled = False
                testLevel = 0
                progressTest.Progress = 0
                errorsLabel.Text = "Errori: " & errorsTotal
                timePassed = 0
                minutes = 0
                timeLabel.Text = "Tempo: 00m : 00s"
                
                
                'introLabel.Text = "Clicca ""Nuovo Livello"" per Iniziare"
                SetLabelSize(introLabel, "Clicca ""Nuovo Livello"" per Iniziare")
            End If
        
            
        
        Else
            
            errorsTotal = errorsTotal + 1
            errorsLabel.Text = " Errori: " & errorsTotal
            
            If errorsTotal = 1 Then
                errorString = "Errore"
            Else
                errorString = "Errori"
            End If
            
            Msgbox("La risposta alla domanda n° " & testLevel & " è sbagliata! Hai accumulato un totale di " & errorsTotal & " " & errorString & ".", "Attenzione")
            'pulisco la edittext
'            resultField.Text = ""
        
            
        End If
    
    
    End If
    

    
    
End Sub

'questo serve a modificare la grandezza del testo nella label
Sub SetLabelSize(lbl As Label, txt As String)
    Dim dt As Float
    Dim limit = 0.5 As Float
    Dim h As Int
  
    lbl.Text = txt
    lbl.TextSize = 72
    dt = lbl.TextSize
    h = stu.MeasureMultilineTextHeight(lbl, txt)
    Do While dt > limit Or h > lbl.Height
        dt = dt / 2
        h = stu.MeasureMultilineTextHeight(lbl, txt)
        If h > lbl.Height Then
            lbl.TextSize = lbl.TextSize - dt
            lbl.TextSize = lbl.TextSize - 1 'ho aggiunto questo meno 1 se no a volte la scritta era grande e non si leggeva
        Else
            lbl.TextSize = lbl.TextSize + dt
            lbl.TextSize = lbl.TextSize - 1 'ho aggiunto questo meno 1 se no a volte la scritta era grande e non si leggeva
        End If
    Loop
End Sub
    

'questo serve a modificare la grandezza del testo nel bottone
Sub SetButtonTextSize(lbl As Button, txt As String)
    Dim dt As Float
    Dim limit = 0.5 As Float
    ' Dim limit = 1 As Float
    Dim h As Int
  
    lbl.Text = txt
    lbl.TextSize = 72
    dt = lbl.TextSize
    h = stu.MeasureMultilineTextHeight(lbl, txt)
    Do While dt > limit Or h > lbl.Height
        dt = dt / 2
        h = stu.MeasureMultilineTextHeight(lbl, txt)
        If h > lbl.Height Then
            lbl.TextSize = lbl.TextSize - dt
            lbl.TextSize = lbl.TextSize - 2 'ho aggiunto questo meno 2 se no era grande e andava fuori dal bottone
        Else
            lbl.TextSize = lbl.TextSize + dt
            lbl.TextSize = lbl.TextSize - 2 'ho aggiunto questo meno 2 se no era grande e andava fuori dal bottone
        End If
    Loop
End Sub



Sub panelButton_Click
    
    Panel1.Visible = False
    
End Sub



Sub FindDate
    
    Dim year As Int = DateTime.GetYear(DateTime.Now)
    Dim month As Int = DateTime.GetMonth(DateTime.Now)
    Dim day As Int = DateTime.GetDayOfMonth(DateTime.Now)
    Dim hour As Int = DateTime.GetHour(DateTime.Now)
    Dim minute As Int = DateTime.GetMinute(DateTime.Now)
    
    monthTodayString = month
    dayTodayString = day
    yearTodayString = year
    
    Log(dayTodayString & "/" & monthTodayString & "/" & yearTodayString & " ora: " & hour & " :" & minute)
    
End Sub


Sub RegisterResults(minutesInt As Int, secondsInt As Int , errorsInt As Int)
    
    Dim List1 As List
    
    'controllo se il foile di testo esiste
    If File.Exists(File.DirRootExternal, "MathTest/ListResult.txt") Then
        
        
        'seil file esiste
        
        'carico i dati dal file di testo
        List1 = File.ReadList(File.DirRootExternal, "MathTest/ListResult.txt")
        
        Dim trovato As Boolean
        trovato = False
        
        For i = 0 To 99
            
            ListResult(i) = List1.Get(i)
            
            If ListResult(i) = "0" And trovato = False Then
                
                'riempio lo slot dell'array con i valori da registrare
                ListResult(i) = dayTodayString & "|" & monthTodayString & "|" & yearTodayString & "|" & minutesInt & "|" & secondsInt & "|" & errorsInt
                
                'imposto la booleam in True
                trovato = True
                
                
            End If
            
            
        Next
        
        
        'se trova tutti gli slot occupati cancella il primo
        If trovato = False Then
            
            For 1 = 1 To 99
'                ListResult(i-1) = ListResult(i)
            Next
        End If
        
        'salvo la array nel file di testo
        File.WriteList(File.DirRootExternal, "MathTest/ListResult.txt",ListResult)
        
    Else  'se il file non esiste
            
        For i = 0 To 99
            ListResult(i) = "0"
        Next
            
        ListResult(99) = dayTodayString & "|" & monthTodayString & "|" & yearTodayString & "|" & minutesInt & "|" & secondsInt & "|" & errorsInt
        
        'creo la directory
        File.MakeDir(File.DirRootExternal, "MathTest")
        
        'salvo la array nel file di testo
        File.WriteList(File.DirRootExternal, "MathTest/ListResult.txt",ListResult)
        
        
        
    End If
    
    
    
End Sub

Sub listButton_Click
    StartActivity(List)
End Sub


Sub Activity_KeyPress (KeyCode As Int) As Boolean
    
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        
        'se il panel è aperto lo chiudo con il tasto indietro del cell
        If Panel1.Visible = True Then
            Panel1.Visible = False
            Return True
        
        End If
    End If
    Return False
End Sub



Sub infoButton_Click
    StartActivity(Info)
End Sub



Sub buttonD_Click
''    Dim minuteString As String
''    Dim secondString As String
    Dim errorString As String
    
    If testLevel = 0 Then
        testLevel = 1
        questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
        CreateCalculation
        'introLabel.Text = "Scrivi qui il risultato"
        SetLabelSize(introLabel, "Schegli il risultato esatto")
        timer1.Enabled = True
'        SetButtonTextSize(okButton, "OK!")
'        okButton.Visible = False  'disattivo il bottone ok dopo l'avvio del tempo
        
    
            
    Else    If buttonD.Text = resultInt Then
        
        
            
        testLevel = testLevel + 1
        
        'pulisco la edittext
'            resultField.Text = ""
        ToastMessageShow("Risposta Giusta!",True)
            
        questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
        progressTest.Progress = progressTest.Progress + 1 'aumenta la progressbar ad ogni livello
    Else
        errorsTotal = errorsTotal + 1
        errorsLabel.Text = " Errori: " & errorsTotal
            
        If errorsTotal = 1 Then
            errorString = "Errore"
        Else
            errorString = "Errori"
        End If
            
        Msgbox("La risposta alla domanda n° " & testLevel & " è sbagliata! Hai accumulato un totale di " & errorsTotal & " " & errorString & ".", "Attenzione")
        'pulisco la edittext
'            resultField.Text = ""
'           
        If testLevel < (indexMax+1) Then
            CreateCalculation
        
        
            
        End If
    End If

'    Dim numbers (10) As Int
'   
'    For i = 0 To 9
'        numbers(i) = i + 1
'    Next
'    ShuffleArray(numbers)
'    For i = 0 To 9
'        Log(numbers(i))
'    Next

End Sub

Sub buttonC_Click
'    Dim minuteString As String
'    Dim secondString As String
    Dim errorString As String
    
    If testLevel = 0 Then
        testLevel = 1
        questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
        CreateCalculation
        'introLabel.Text = "Scrivi qui il risultato"
        SetLabelSize(introLabel, "Schegli il risultato esatto")
        timer1.Enabled = True
'        SetButtonTextSize(okButton, "OK!")
'        okButton.Visible = False  'disattivo il bottone ok dopo l'avvio del tempo
        
    
            
    Else    If buttonC.Text = resultInt Then
        

            
        testLevel = testLevel + 1
        
        'pulisco la edittext
'            resultField.Text = ""
        ToastMessageShow("Risposta Giusta!",True)
            
        questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
        progressTest.Progress = progressTest.Progress + 1 'aumenta la progressbar ad ogni livello
    Else
        errorsTotal = errorsTotal + 1
        errorsLabel.Text = " Errori: " & errorsTotal
            
        If errorsTotal = 1 Then
            errorString = "Errore"
        Else
            errorString = "Errori"
        End If
            
        Msgbox("La risposta alla domanda n° " & testLevel & " è sbagliata! Hai accumulato un totale di " & errorsTotal & " " & errorString & ".", "Attenzione")
        'pulisco la edittext
'            resultField.Text = ""
'           
        If testLevel < (indexMax+1) Then
            CreateCalculation
        
        
            
        End If
    End If


    
End Sub

Sub buttonB_Click
    Dim minuteString As String
    Dim secondString As String
    Dim errorString As String
    
    Dim num1 As Int
    Dim num2 As Int
    Dim num3 As Int
    Dim num4 As Int
    Dim num5 As Int
    Dim num6 As Int
    
    If testLevel = 0 Then
        testLevel = 1
        questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
        CreateCalculation
        'introLabel.Text = "Scrivi qui il risultato"
        SetLabelSize(introLabel, "Schegli il risultato esatto")
        timer1.Enabled = True
'        SetButtonTextSize(okButton, "OK!")
'        okButton.Visible = False  'disattivo il bottone ok dopo l'avvio del tempo
        
    
            
    Else    If buttonB.Text  = resultInt Then
        
        

            
        testLevel = testLevel + 1
        
        'pulisco la edittext
'            resultField.Text = ""
        ToastMessageShow("Risposta Giusta!",True)
            
        questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
        progressTest.Progress = progressTest.Progress + 1 'aumenta la progressbar ad ogni livello
    Else
        errorsTotal = errorsTotal + 1
        errorsLabel.Text = " Errori: " & errorsTotal
            
        If errorsTotal = 1 Then
            errorString = "Errore"
        Else
            errorString = "Errori"
        End If
            
        Msgbox("La risposta alla domanda n° " & testLevel & " è sbagliata! Hai accumulato un totale di " & errorsTotal & " " & errorString & ".", "Attenzione")
        'pulisco la edittext
'            resultField.Text = ""
'           
        If testLevel < (indexMax+1) Then
            CreateCalculation
        
        
            
        End If
        
        If minutes = 1 Then
            minuteString = "minuto"
        Else
            minuteString = "minuti"
        End If
                
        If timePassed = 1 Then
            secondString = "secondo"
        Else
            secondString = "secondi"
        End If
                
        If errorsTotal = 1 Then
            errorString = "Errore"
        Else
            errorString = "Errori"
        End If
        
    End If

    
End Sub

'Sub ShuffleArray(arr() As Int)
'    For i = arr.Length - 1 To 0 Step -1
'        Dim j, k As Int
'        j = Rnd(0, i +1)
'        k = arr(j)
'        arr(j) = arr (i)
'        arr(i) = k
'    Next
'End Sub

Sub buttonA_Click
    Dim minuteString As String
    Dim secondString As String
    Dim errorString As String
    
    Dim num1 As Int
    Dim num2 As Int
    Dim num3 As Int
    Dim num4 As Int
    Dim num5 As Int
    Dim num6 As Int
    
    
    
    If testLevel = 0 Then
        testLevel = 1
        questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
        CreateCalculation
        introLabel.Text = "Scrivi qui il risultato"
        SetLabelSize(introLabel, "Schegli il risultato esatto")
        timer1.Enabled = True
        SetButtonTextSize(okButton, "OK!")
        okButton.Visible = False  'disattivo il bottone ok dopo l'avvio del tempo
        

            
    Else If buttonA.Text  = resultInt Then
        
        buttonA.Text = buttonA.Text +10

        
        testLevel = testLevel + 1
'        pulisco la edittext
'        resultField.Text = ""
        ToastMessageShow("Risposta Giusta!",True)
        
'            mathLabel.Text = ""
'                resultField.Text = ""
        'okButton.Text = "Nuovo Livello"
        SetButtonTextSize(okButton, "Nuovo Livello!")
        questionNumLabel.Text = "Domanda N°: " 'livello nella label
        
        questionNumLabel.Text = "Domanda N°: " & testLevel 'livello nella label
        progressTest.Progress = progressTest.Progress + 1 'aumenta la progressbar ad ogni livello
            
    Else
'        buttonA.Text = Rnd(1,101)
            
        errorsTotal = errorsTotal + 1
        errorsLabel.Text = " Errori: " & errorsTotal
            
        If errorsTotal = 1 Then
            errorString = "Errore"
        Else
            errorString = "Errori"
        End If
            
        Msgbox("La risposta alla domanda n° " & testLevel & " è sbagliata! Hai accumulato un totale di " & errorsTotal & " " & errorString & ".", "Attenzione")
        'pulisco la edittext
'            resultField.Text = ""
        '-------------------------------------------------------------------------------------------
          
        If testLevel < (indexMax+1) Then
            CreateCalculation
        End If
        
        If minutes = 1 Then
            minuteString = "minuto"
        Else
            minuteString = "minuti"
        End If
                
        If timePassed = 1 Then
            secondString = "secondo"
        Else
            secondString = "secondi"
        End If
                
        If errorsTotal = 1 Then
            errorString = "Errore"
        Else
            errorString = "Errori"
        End If
    
    End If
    If errorsTotal = 0 Then
        'imposto i valori nel panel1
        SetLabelSize(panelTitleLabel, "Complimenti!")
        SetLabelSize(panelLabel, "Il test è terminato, hai risposto ad un totale di " & indexMax & " domande senza nessun errore in " & minutes & " " & minuteString & " e " & timePassed & " " & secondString & ". Sei un Drago della Matematica!")
                    
                    
    Else If errorsTotal < 3 Then
        'imposto i valori nel panel1
        SetLabelSize(panelTitleLabel, "Ben Fatto!")
        SetLabelSize(panelLabel, "Il test è terminato, hai risposto ad un totale di " & indexMax & " domande , con un totale di " & errorsTotal & " " & errorString & " , in " & minutes & " " & minuteString & " e " & timePassed & " " & secondString & ". Puoi Fare di Meglio")
                    
    Else
        'imposto i valori nel panel1
        SetLabelSize(panelTitleLabel, "Test Fallito")
        SetLabelSize(panelLabel, "Il test è terminato, hai risposto ad un totale di " & indexMax & " domande , con un totale di " & errorsTotal & " " & errorString & " , in " & minutes & " " & minuteString & " e " & timePassed & " " & secondString & ". Devi Studiare di Più :P")
                    

    
    
                
                
        RegisterResults(minutes,timePassed,errorsTotal)
        
        
        Panel1.Visible = True
                
                
        timer1.Enabled = False
        testLevel = 0
        progressTest.Progress = 0
        errorsLabel.Text = "Errori: " & errorsTotal
        timePassed = 0
        minutes = 0
        timeLabel.Text = "Tempo: 00m : 00s"
                
                
        'introLabel.Text = "Clicca ""Nuovo Livello"" per Iniziare"
        SetLabelSize(introLabel, "Clicca ""Nuovo Livello"" per Iniziare")
        okButton.Visible = True
End If

End Sub

thanks Antonio
 

MarkusR

Well-Known Member
Licensed User
Longtime User
i don't get what you are trying to do.
maybe provide a smaller example (project) for testing or a screen video where the problem is.
or a diagram / sketch with the sequence.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
you should use File -> Export as zip from the Ide.
 
Upvote 0

Antonio Costa

Member
Licensed User
let's say it's a math test, there are 4 buttons, buttonA, buttonB, buttonC, buttonD, in every one of these buttons there are 4 results, but only one contains the exact result, when the exact result is clicked it goes to the next test, but the button should also change, if in the previous test the buttonA contains the result, the buttonB or buttonD contains the following test result
 

Attachments

  • Screenshot_20180317-161711.png
    Screenshot_20180317-161711.png
    279.2 KB · Views: 246
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i would use a list with type mathtest(no,exercise,answer,mistake).
pick one of the list and put this into gui, put the type object into tag.
at click event you get the data from sender > button > .tag > type
compare text with answer, visualize yes/no.
at yes you goto next one of the list (iterated) , at no disable button and memory mistake.
at end of list show result.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
let's say it's a math test, there are 4 buttons, buttonA, buttonB, buttonC, buttonD, in every one of these buttons there are 4 results, but only one contains the exact result, when the exact result is clicked it goes to the next test, but the button should also change, if in the previous test the buttonA contains the result, the buttonB or buttonD contains the following test result
I saw the code is really a mess ... how much do you develop?

I am attaching an example of how it could, then graphically adjust it as you like ...

P.S. After starting it, click the START button
 

Attachments

  • RandomNumber.zip
    9.7 KB · Views: 243
Upvote 0
Top