Italian numeri random

Antonio Costa

Member
Licensed User
salve a tutti , se possibile mi servirebbe un piccolo consiglio su come risolvere questo pasticcio dei numeri random
, ho cercato di inserire del testo su 4 bottoni , dove uno di loro deve avere un risultato esatto , nel momento in cui clicco sul risultato esempio bottoneA il numero dovrebbe cambiare passando il risultato su un altro bottone , ma il risultato esatto rimane sempre su bottoneA , tranne se io non clicco su un bottoneB andomi errore , allora cambia sia num1 + num2 ma anche il risultato su un altro bottone , credo di aver combinato un bordello nel codice , ti sarei grato se mi daresti un aiuto
grazie Antonio

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
 

Star-Dust

Expert
Licensed User
Longtime User
Manda il codice. Cosi non si capisce bene.

Vai sul menu File e esporta come ZIp e lo alleghi
 

Star-Dust

Expert
Licensed User
Longtime User
Si trova, nell'IDE di B4A.

Comunque ho visto il codice é veramente un casino... sei sicuro di essere sviluppatore?

ti allego un esempio di come andrebbe fatta la gestione delle somme, poi aggiungi timer, livelli e lo aggiusti graficamente come ti pare meglio...

Parte cliccando il bottone START

P.S. Se ogni livello aumentano gli operatori, usa array di Label
 

Attachments

  • RandomNumber.zip
    9.7 KB · Views: 226
Last edited:

Antonio Costa

Member
Licensed User
Si trova, nell'IDE di B4A.

Comunque ho visto il codice é veramente un casino... sei sicuro di essere sviluppatore?

ti allego un esempio di come andrebbe fatta la gestione delle somme, poi aggiungi timer, livelli e lo aggiusti graficamente come ti pare meglio...

P.S. Dopo averlo fatto partire clicca il bottone START
Grazie mille , no sono un po alle prime armi ecco perché mi sono incasinato
 

Star-Dust

Expert
Licensed User
Longtime User
Grazie mille , no sono un po alle prime armi ecco perché mi sono incasinato
Usa Array di Label se crescono le cifre con l'aumentare del livello.

I mesi mettili in un array di Stringhe
B4X:
Sub CalculateMonth(monthTodayString As Int) As String
    Dim Mesi()  As String = Array As String("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre")
   
    Return Mesi(monthTodayString-1)
End If
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
In effetti non solo il codice non è esattamente ben strutturato (per non parlare dei nomi dati a variabili e view, che sono IMPORTANTISSIMI, non usare nomi generici, come Label1, EditText1, ButtonD... MAI, nemmeno per prove velocissime) ma anche la descrizione di ciò che vuoi ottenere, scritta nel primo post.

Mettere le mani sul tuo codice è difficile proprio perché, perlomeno io, non ho capito cosa dovresti ottenere; se spieghi meglio questo, certamente saremo in grado di aiutarti di più.
 

Star-Dust

Expert
Licensed User
Longtime User
Chiedevo a @Star-Dust (solo perché non era stato gentilissimo ;))
Io sono gentilissimo, anzi di più... la mia era solo curiosità.
Non confondiamo la curiosità con scortesia.... :p
 

Antonio Costa

Member
Licensed User
In effetti non solo il codice non è esattamente ben strutturato (per non parlare dei nomi dati a variabili e view, che sono IMPORTANTISSIMI, non usare nomi generici, come Label1, EditText1, ButtonD... MAI, nemmeno per prove velocissime) ma anche la descrizione di ciò che vuoi ottenere, scritta nel primo post.

Mettere le mani sul tuo codice è difficile proprio perché, perlomeno io, non ho capito cosa dovresti ottenere; se spieghi meglio questo, certamente saremo in grado di aiutarti di più.
Il mio intento era ottenere tipo un test di matematica come @Star-Dust mi ha inviato , ma inoltre inserire in una resultText delle addizioni (+) oppure delle riflessioni , seguita dai 4 bottoni con risultati random , basta solo scegliere il risultato esatto
 

Star-Dust

Expert
Licensed User
Longtime User
Fammi un disegnino perché proprio non capisco :D

(il sito in questo momento ha dei lag)
Screenshot_20180317-161711.png
 

Antonio Costa

Member
Licensed User
Fammi un disegnino perché proprio non capisco :D

(il sito in questo momento ha dei lag)
Fai finta che qui ci sarà (9 x 4 ) - ( 3 x 1 ) , e poi tutti a random , naturalmente il + o - oppure il x , lo inserisc e mi calcola tutti numeri casuali
 

Attachments

  • Screenshot_20180317-161711.png
    Screenshot_20180317-161711.png
    279.2 KB · Views: 198

Antonio Costa

Member
Licensed User
questo è come dovrebbe venire , ma ovviamente e tutto incasinato , quando avrò messo a puntino tutto allora eliminerò tutto il di più, solo che voglio cercare di ottenere lo stesso codice che @Star-Dust mi ha mandato , senza cliccare ogni volta sul bottone start , ma i risultati cambiano appena si clicca sul risultato esatto
 

Attachments

  • test.zip
    427.9 KB · Views: 205
Top