Eslay
07-07-2014, 11:29 PM
Hello i have a little problem with VBA, i make some mistake but i dont know where im beginner in VBA. I try to write program which ask me long shoul be string of numer and the i write every one numer. After this operation program should show numbers which i wrote and the lowest numer from this tab/string. Could you help me and tell me where i need to correct my code or correct this program by your owne ?
Function MinTablicy(TabCiag As Variant) As Integer
Dim WartMin As Integer
Dim IndeksDolny As Long, IndeksGorny As Long, i As Long
IndeksDolny = LBound(TabCiag)
IndeksGorny = UBound(TabCiag)
WartMin = TabCiag(IndeksDolny)
For i = IndeksDolny To IndeksGorny
If TabCiag(i) < WartMin Then WartMin = TabCiag(i)
Next
MinTablicy = WartMin
End Function
Sub CommandButton3_Click()
Dim ss As Long
Dim TabCiag() As Integer
Dim numerki As String ' wpisane numery
Dim i As Long
numerki = " "
ss = TextBox4.Text
If ss = 0 Then
MsgBox ("Ciag ma zerowa dlugosc ")
ElseIf ss < 0 Then
MsgBox ("Ciag nie moze byc ujemny")
Else
For i = 1 To ss
ReDim TabCiag(i)
TabCiag(i) = InputBox("Podaj liczbe " & i, "Liczba")
numerki = numerki + Str(TabCiag(i))
Next i
MsgBox "Wpisanow numery : " & numerki, , "LICZBY"
MsgBox "Minimalana wartość z tablicy to: " & MinTablicy(TabCiag)
End If
End Sub
Thx for your help
Function MinTablicy(TabCiag As Variant) As Integer
Dim WartMin As Integer
Dim IndeksDolny As Long, IndeksGorny As Long, i As Long
IndeksDolny = LBound(TabCiag)
IndeksGorny = UBound(TabCiag)
WartMin = TabCiag(IndeksDolny)
For i = IndeksDolny To IndeksGorny
If TabCiag(i) < WartMin Then WartMin = TabCiag(i)
Next
MinTablicy = WartMin
End Function
Sub CommandButton3_Click()
Dim ss As Long
Dim TabCiag() As Integer
Dim numerki As String ' wpisane numery
Dim i As Long
numerki = " "
ss = TextBox4.Text
If ss = 0 Then
MsgBox ("Ciag ma zerowa dlugosc ")
ElseIf ss < 0 Then
MsgBox ("Ciag nie moze byc ujemny")
Else
For i = 1 To ss
ReDim TabCiag(i)
TabCiag(i) = InputBox("Podaj liczbe " & i, "Liczba")
numerki = numerki + Str(TabCiag(i))
Next i
MsgBox "Wpisanow numery : " & numerki, , "LICZBY"
MsgBox "Minimalana wartość z tablicy to: " & MinTablicy(TabCiag)
End If
End Sub
Thx for your help