Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

VB 6.0 i matematika

[es] :: Visual Basic 6 :: VB 6.0 i matematika

[ Pregleda: 1619 | Odgovora: 12 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

One_side
Goran Kovačević
Sarajevo

Član broj: 104551
Poruke: 7
*.europronet.ba.



Profil

icon VB 6.0 i matematika10.08.2006. u 00:53 - pre 216 meseci
Pomoć molim vas, evo problema:
Code:

c = 1000
If command1 = True Then
b = Text1.text
i = 0
Do While  b >= c
i = i + 1
b = b / c
Loop
Text2.Text = b
Text3.Text = c
Text4.Text = i 
End If

problem mi se javlja ako je b broj koji ima više od 310 cifara ili len (b) > 310, Visual Basic 6.0 mi javi da se radi o "run - time error 6 - Overflow" ima li ikakav način da se ukine ovo ograničenje?

Drugi problem mi se javlja kada želim da iz ovih podataka, koje dobijem(b, c, i), vratim prvobitni broj.
Code:

If Command2 = True Then 
b = Text2.Text
i = Text4.Text
L = c ^ i
T = L * b
Text1.Text = T
End If

da naglasim da je c konstanta na nivou modula = 1000

primjer za drugi problem:

Broj koji sam pretvarao pomoću command1 je: 1000000000000000000000000000000000 / 1000
i dobijem da mi je b = 100
c = 1000
i = 10
kad ove podatke uvrstim u command2 dobijem 1E+32 kako da mi Visual Basic 6.0 vrati broj bez ovog E+32 nego da su tu nule kao kod početnog broja?
Pomažite kako znate....

[Ovu poruku je menjao One_side dana 10.08.2006. u 16:29 GMT+1]

[Ovu poruku je menjao krckoorascic dana 11.08.2006. u 03:21 GMT+1]
Seeking
 
Odgovor na temu

Fuzz
Bojan Vukovic
Novi Sad

Član broj: 8631
Poruke: 3866
212.200.155.*



+9 Profil

icon Re: VB 6.0 i matematika10.08.2006. u 10:48 - pre 216 meseci
Pitanje 1. Kako ti je taj b dimenzionisan?
Pitanje 2. Sta ce ti 310+ cifreni broj?
anti-heroin spree
 
Odgovor na temu

One_side
Goran Kovačević
Sarajevo

Član broj: 104551
Poruke: 7
*.europronet.ba.



Profil

icon Re: VB 6.0 i matematika10.08.2006. u 11:01 - pre 216 meseci
b je dim as Variant, imam neku knjigu u kojoj se navodi samo nekoliko vrsta podataka pa mi se ovaj učinio nekako najpogodnijim, to je automatski tip podatka jer ja nisam ništa dimenzionisao posebno
A 310+ pravim digitron koji će moći operisati sa takvim brojevima, moj otac je dipl.ing. mašinstva pa kaže da bi mu takva stvarčica dobro došla.
Seeking
 
Odgovor na temu

Not now, John!

Član broj: 231
Poruke: 1318
87.250.104.*



+4 Profil

icon Re: VB 6.0 i matematika10.08.2006. u 11:11 - pre 216 meseci
Imaš negdje u Help sistemu tipove podataka koje podržava VB i njihov opseg.
Probaj da koristiš Float tip podataka.
"I'd take the awe of understanding over the awe of ignorance any day."
- Douglas Adams
 
Odgovor na temu

One_side
Goran Kovačević
Sarajevo

Član broj: 104551
Poruke: 7
*.europronet.ba.



Profil

icon Re: VB 6.0 i matematika10.08.2006. u 14:22 - pre 216 meseci
Ma za tipove podataka mi je jasno to sam našao ali ovo za Float mi je totalna nepoznanica, stvarno nemam veze sta je to. To je kako meni izgleda za napredne korisnike a ne za početnike kao što sam ja. Ako nije problem možeš li detaljnije kako se taj tip podataka koristi na mom primjeru? hvala.

Seeking
 
Odgovor na temu

mLAN
Novi Sad

Član broj: 85738
Poruke: 404



Profil

icon Re: VB 6.0 i matematika10.08.2006. u 14:31 - pre 216 meseci
Pa u prvom primeru nemaš inicijalizovano c. Tako da if c = 0 then b -> beskonačno.

Ostalo nisam baš najbolje skontao šta si hteo reći (pokušao sam pročitati 2 puta ali...)
 
Odgovor na temu

Fuzz
Bojan Vukovic
Novi Sad

Član broj: 8631
Poruke: 3866
212.200.155.*



+9 Profil

icon Re: VB 6.0 i matematika10.08.2006. u 14:34 - pre 216 meseci
Radi se o pokretnom zarezu, tj. floating point-u.
Floating point tip podataka moze biti single i double.
Ako ga definises kao double, znaci napises
Code:
Dim b as Double
maksimalna pozitivna vrednost za b moze biti 1.79769313486232E+308

Ako si b definisao kao variant i radis sa numerickim vrednostima, maksimalna vrednost ce biti jednaka maksimalnoj vrednosti double promenljive.

BTW, sta cale projektuje na 300 decimala mame ti? Kao dosad je rucno radio pa ti da mu nabudzis na racunaru :)
anti-heroin spree
 
Odgovor na temu

One_side
Goran Kovačević
Sarajevo

Član broj: 104551
Poruke: 7
*.europronet.ba.



Profil

icon Re: VB 6.0 i matematika10.08.2006. u 15:40 - pre 216 meseci
maksimalna pozitivna vrednost za b moze biti 1.79769313486232E+308

Ako si b definisao kao variant i radis sa numerickim vrednostima, maksimalna vrednost ce biti jednaka maksimalnoj vrednosti double promenljive.

Ovaj mi je broj kratak :(

A za starog, veze nemam šta radi samo kad sam mu ja to rekao šta radim, on mi je rekao što sam naveo.
Možda je to bilo "sine kani se čorava posla al hajde barem se nećeš drogirati". :)

[Ovu poruku je menjao One_side dana 10.08.2006. u 16:51 GMT+1]
Seeking
 
Odgovor na temu

One_side
Goran Kovačević
Sarajevo

Član broj: 104551
Poruke: 7
*.europronet.ba.



Profil

icon Re: VB 6.0 i matematika10.08.2006. u 15:48 - pre 216 meseci
mLAN

c je konstanta na nivou modula ali sam je dopisao da je vidiš.
kako koristiti Visual Basic da podijeli broj koji ima više od 310 cifri sa c = 1000
koristim variant tip podataka i njegova maksimalna vrijednost je 1.79769313486232E+308 a meni treba mogučnost izvođenja računskih radnji sa brojevima veće vrijednosti i dužine svakako.

Za drugi dio pitanja me zanima kad izarčunaš primjer koji sam ja naveo dobiješ 1E+32, postoji li procedura koja će vratiti broj ali ne u ovom obliku nego u obliku:1000000000000000000000000000000000 ovog finog dugog broja. :)
Seeking
 
Odgovor na temu

icobh
Igor Pejašinović
Network Admin
Navigo SC d.o.o.
Banja Luka

Član broj: 18738
Poruke: 1319
*.inecco.net.

Sajt: www.nsc.ba


+4 Profil

icon Re: VB 6.0 i matematika10.08.2006. u 16:14 - pre 216 meseci
Neko je od mojih kolega sa faxa imao zadatak da napravi program u C-u, koji će raditi sa 100+ cifrenim brojevima, tj. vršiti njihovo sabiranje, oduzimanje, dijeljenje i množenje. Baš taj kolega me pitao za ideju, meni prvo tada što je napameti bilo, jeste da se brojevi unose kao stringovi, pa da se barata sa karakterima unutar stringa. Možda ti ova ideja pomogne...
I ♥ ♀

Ovaj post je zlata vrijedan!
 
Odgovor na temu

One_side
Goran Kovačević
Sarajevo

Član broj: 104551
Poruke: 7
*.europronet.ba.



Profil

icon Re: VB 6.0 i matematika10.08.2006. u 17:05 - pre 216 meseci
icobh


Možda bi moglo da i upali, odoh da probam, Hvala.

Seeking
 
Odgovor na temu

Shadowed
Vojvodina

Član broj: 649
Poruke: 12851



+4784 Profil

icon Re: VB 6.0 i matematika10.08.2006. u 17:36 - pre 216 meseci
Jos bolja varijanta je da pre toga konvertujes taj string u niz integer-a (ili byte-a, zavisno da li ti je bitnija brzina ili zauzece RAM-a).
 
Odgovor na temu

One_side
Goran Kovačević
Sarajevo

Član broj: 104551
Poruke: 7
*.europronet.ba.



Profil

icon Re: VB 6.0 i matematika11.08.2006. u 01:51 - pre 216 meseci
Nije upalilo imam nesto sto bi moglo da pa cu ga i postaviti ovdje, vidite znali itko sta to znaci. Kreator tvrdi da može operisati sa beskonačno velikim brojevima, gotovo beskonačno velikim.
Pogledajte zna li iko kako ovo funkcioniše i ako zna molim vas da mi to rastumaći jer sam ja stvarno početnik i samo mali dio ovoga mi je jasan, pa evo :
Code:

'I created this code because I found that sometimes
'an unwated overflow error would occur. So I coded
'this, this supports Adding, Subtracting,
'Multiplication and Division however at the moment this doesn't
'support decimals. This code was also designed for maximum speed
'with minimal errors. (Hopefully none, although I realy should
'have put error handling in, mabey next version). This also has support
'for negative numbers and if you have a look at this code the
'Adding and Subtrating can depend on eachother. As you may
'notice I try and avoid using the full number. Hope this helps
'at least someone out there. :)


Const MaxLen As Long = 1000
'The constand 'MaxLen' is just the max length of any
'number to be processed and the final number, if you need longer
'numbers then go ahead and change it.
Global Number1(1 To MaxLen) As Integer
Global Number2(1 To MaxLen) As Integer
Global FinalNum(1 To MaxLen) As Integer
'These Globals here just store the numbers. 'Number1' and 'Number2'
'Are the numbers being processed, and 'FinalNum' is output and is
'processed into a string.
Dim X As Long
Dim Y As Long
'X is a number used for a loop when manipulating the numbers
Dim tempstr As String
Dim tempstrB As String
Dim tempstrC As String
'These are just strings to hold the numbers temporaraly
Dim tempint As Long
Dim tempintB As Long
Dim GotInt As Boolean
Dim Negative As Boolean
'The boolean 'GotInt' is used in the 'PutTogether' function
'so that we don't end up with allot of 0's infrount of the number
'and the boolean 'Neagtive' tells us if we have a negative number or
'not.
Dim LenDec1 As Long
Dim LenDec2 As Long
'These two 'longs' are for storing the position of the decimal place.
'We do this because we remove the decimal place so it's easier to process.
Dim PutInPos As Integer

Public Sub SplitNums(IntA As String, IntB As String)
'This sub splits the stings, AKA the two numbers being procesed,
'into an array where only one number is stored.
LenDec1 = InStr(1, IntA, ".")
If Not LenDec1 = 0 Then
    LenDec1 = Len(IntA) - LenDec1
    IntA = Replace(IntA, ".", "")
End If

LenDec2 = InStr(1, IntB, ".")
If Not LenDec2 = 0 Then
    LenDec2 = Len(IntB) - LenDec2
    IntB = Replace(IntB, ".", "")
End If

If Not LenDec1 = LenDec2 Then
    If LenDec1 < LenDec2 Then
        For X = 1 To LenDec2 - LenDec1
            IntA = IntA & "0"
            DoEvents
        Next
        Else
        For X = 1 To LenDec1 - LenDec2
            IntB = IntB & "0"
            DoEvents
        Next
        
    End If
End If
    

If MaxLen <= Len(IntA) Or Len(IntB) Then
'This checks if the max length is longer then either
'of the numbers. If it is then it continues on, if not
'then nothing happens.
        
    For X = 1 To Len(IntA)
    'This is a loop of sorts that splits up the first number and
    'puts it into an array
        Number1(X) = Mid(IntA, Len(IntA) - X + 1, 1)
        DoEvents
    Next

    For X = 1 To Len(IntB)
    'This is a loop that splits up the second number and
    'puts it into an array
        Number2(X) = Mid(IntB, Len(IntB) - X + 1, 1)
        DoEvents
    Next

End If
End Sub

Public Sub ResetVars()
'This sub resets the values that each function uses. This
'is realy only used because if you don't then it's posiable
'to mix results from previous calculations.
Negative = False
GotInt = False
For X = 1 To MaxLen
    Number1(X) = 0
    Number2(X) = 0
    FinalNum(X) = 0
Next
End Sub

Public Function PutTogether(MathType As Integer) As String
'This function puts the numbers together, in the proper order
'as you may have noticed when the numbers are stored they are
'stored from right to left and not the other way around, this
'is because not every number has the same length, and it's much
'easier to 'line up' the numbers.

tempstr = ""
'We make tempstr = "" because if we don't the we could get a mix
'of results. Eg, the last answer was "232" and this one is "643",
'if we didn't clear this string then it would be "232643"
DoEvents

If MathType = 1 Then
    'Addition
    If LenDec1 > LenDec2 Then
        PutInPos = LenDec1
        Else
        PutInPos = LenDec2
    End If
    ElseIf MathType = 2 Then
    'Subtraction
    If LenDec1 > LenDec2 Then
        PutInPos = LenDec1
        Else
        PutInPos = LenDec2
    End If
    ElseIf MathType = 3 Then
    'Multiplication
    PutInPos = LenDec1 + LenDec2
    
    ElseIf MathType = 4 Then
    'Division
    
End If

DoEvents
For X = MaxLen To 1 Step -1
    If X = Int(PutInPos) Then
        tempstr = tempstr & "."
    End If
    DoEvents
    If FinalNum(X) = 0 And GotInt = False Then
    'This if statement checks if the curent number is zero and if
    'we already have a number. If we don't have anything then we don't
    'bother to add the zero because it is useless info.
        Else
        GotInt = True
        tempstr = tempstr & FinalNum(X)
    'This part her just adds the numbers
    End If
Next

PutTogether = tempstr
'Once this loop is done we let the function know what the result is.
End Function

Public Function AddNum(Base As String, AddAmount As String) As String
'This Function is self explainitary in what it does, but I'll still explain.
'It adds numbers together.
ResetVars
'We reset the varaiables or else we could get mixed results.
DoEvents

If Left(Base, 1) = "-" And Left(AddAmount, 1) = "-" Then
'This if statement checks if we have negetive numbers. If both
'are negative we remove the minus signs and set the boolean
' 'negative' to true so when we get to the end we get a minus
'at the start of the number. If only one is a negitive number then we
'start the subtraction function and set the result of that as the result
'of this.
    Negative = True
    Base = Right(Base, Len(Base) - 1)
    AddAmount = Right(AddAmount, Len(AddAmount) - 1)

    ElseIf Left(Base, 1) = "-" Then
    tempstrB = SubNum(AddAmount, Right(Base, Len(Base) - 1))
    AddNum = tempstrB
    Exit Function

    ElseIf Left(AddAmount, 1) = "-" Then
    tempstrB = SubNum(Base, Right(AddAmount, Len(AddAmount) - 1))
    AddNum = tempstrB

    Exit Function

End If

SplitNums Base, AddAmount
'This splits the numbers so we can manipulate them easily

If Len(Base) > Len(AddAmount) Then
    tempint = Len(Base)
    Else
    tempint = Len(AddAmount)
End If
'This if statement finds out how may times we have to loop

For X = 1 To tempint
    FinalNum(X) = Int(Number1(X)) + Int(Number2(X)) + Int(FinalNum(X))
    'We add the numbers together and then we check wether it's larger or
    'or equal to the number 10. If it is we subtract 10 and add 1 to the next
    'number
    If FinalNum(X) >= 10 Then
        FinalNum(X) = Int(FinalNum(X)) - 10
        FinalNum(X + 1) = 1
    End If
Next

AddNum = PutTogether(1)
'This puts the individual numbers together again in the right order
If Negative = True Then
    AddNum = "-" & AddNum
End If
'If this number was a negitive number then we add the minus sign infrount
'of it
If AddNum = "" Then AddNum = 0
'If the number is blank for some strange reason it is then changed to 0
End Function

Public Function SubNum(Base As String, SubAmount As String) As String
'This function is also self explanitory but it basicaly subtracts numbers.
ResetVars
'This sub restarts the variables so errors are less likely
DoEvents

If Left(Base, 1) = "-" And Left(SubAmount, 1) = "-" Then
'This if statement checks if both numbers are negative, if so
'it gets rid of their minus signs and switches them around.
'If there is only one minus sign then it adds the numbers together
'and depending on which one is negative it adds a negitive sign to the
'result.
    tempstrC = Right(Base, Len(Base) - 1)
    Base = Right(SubAmount, Len(SubAmount) - 1)
    SubAmount = tempstrC
    
    ElseIf Left(Base, 1) = "-" Then
    tempstrC = AddNum(Right(Base, Len(Base) - 1), SubAmount)
    SubNum = "-" & tempstrC
    Exit Function
    
    ElseIf Left(SubAmount, 1) = "-" Then
    tempstrC = AddNum(Right(SubAmount, Len(SubAmount) - 1), Base)
    SubNum = tempstrC
    Exit Function
End If

If Base > SubAmount Then
'This if statement decides on which number is larger and splits the numbers
'acordingley.
    SplitNums Base, SubAmount
    Else
    Negative = True
    SplitNums SubAmount, Base
End If

If Len(Base) > Len(SubAmount) Then
'This if statement finds out how many times it should loop.
    tempint = Len(Base)
    Else
    tempint = Len(SubAmount)
End If

For X = 1 To tempint
    FinalNum(X) = Int(Number1(X)) - Int(Number2(X)) + Int(FinalNum(X))
    'This subtracts the numbers
    If FinalNum(X) < 0 Then
    'This if Statement checks if the number is less then zero and if it is
    'then it adds 10 to the curent number and sets the next number to -1
        FinalNum(X) = Int(FinalNum(X)) + 10
        
        FinalNum(X + 1) = -1
        
    End If
Next

SubNum = PutTogether(2)
If Negative = True Then
    SubNum = "-" & SubNum
End If
'This checks if a negative sign is needed then if it is it adds it.

If SubNum = "" Then SubNum = 0
'If we didn't get a result then we set it to zero. This can occur if
'we are subtracting the same two numbers.
End Function

Public Function MultiplyNum(Base As String, MultiNum As String)
ResetVars
'This resets the variables
DoEvents

If Left(Base, 1) = "-" And Left(MultiNum, 1) = "-" Then
'This if statement decides wether or not the result will be
'negative or not and ajusts the values acordingly
    Base = Right(Base, Len(Base) - 1)
    MultiNum = Right(MultiNum, Len(MultiNum) - 1)
    
    ElseIf Left(MultiNum, 1) = "-" Then
    Negative = True
    MultiNum = Right(MultiNum, Len(MultiNum) - 1)
    
    ElseIf Left(Base, 1) = "-" Then
    Negative = True
    Base = Right(Base, Len(Base) - 1)
    
End If

SplitNums Base, MultiNum
'This splits the numbers so they can be processed

tempint = Len(Base)
tempintB = Len(MultiNum)
'As you may have noticed we are using two variables to process
'this time. The reason for this is because doing this is like
'doing long multiplacation, therefore making the program
'work faster then if we tried to do it any other way.

For X = 1 To tempint
    For Y = 1 To tempintB
        FinalNum(X + Y - 1) = FinalNum(X + Y - 1) + (Number1(X) * Number2(Y))
    Next
Next
'This is basicaly doing the math here, and making sure we
'don't loose any data, it is posiable for us to get and overflow
'error here. However it's highly unlikely this will happen, however if
'it does occur too often then you can change the dim from an 'integer' to
'a 'long'


For X = 1 To MaxLen
    If FinalNum(X) > 10 Then
        FinalNum(X + 1) = Int(Left(FinalNum(X), Len(FinalNum(X)) - 1)) + Int(FinalNum(X + 1))
        FinalNum(X) = Right(FinalNum(X), 1)
    End If
Next
'This sub proceseses the numbers so that we don't have more then one
'character for each value
DoEvents
MultiplyNum = PutTogether(3)


If Negative = True Then
    MultiplyNum = "-" & MultiplyNum
End If
'This just adds the negative to the start of the number, that is if
'it is a negative number
If MultiplyNum = "" Then MultiplyNum = 0
End Function

Public Function DivideNum(Base As String, DivByNum As String)
ResetVars
'This clears the variables...
DoEvents

LenDec1 = InStr(1, Base, ".")
If Not LenDec1 = 0 Then
    LenDec1 = Len(Base) - LenDec1
    Base = Replace(Base, ".", "")
End If

LenDec2 = InStr(1, DivByNum, ".")
If Not LenDec2 = 0 Then
    LenDec2 = Len(DivByNum) - LenDec2
    DivByNum = Replace(DivByNum, ".", "")
End If

If Not LenDec1 = LenDec2 Then
    If LenDec1 < LenDec2 Then
        For X = 1 To LenDec2 - LenDec1
            Base = Base & "0"
            DoEvents
        Next
        Else
        For X = 1 To LenDec1 - LenDec2
            DivByNum = DivByNum & "0"
            DoEvents
        Next
        
    End If
End If

If Left(Base, 1) = "-" And Left(DivByNum, 1) = "-" Then
'This if statement figures wether or not the result
'will be negative.
    Base = Right(Base, Len(Base) - 1)
    DivByNum = Right(DivByNum, Len(DivByNum) - 1)
    
    ElseIf Left(DivByNum, 1) = "-" Then
    Negative = True
    DivByNum = Right(DivByNum, Len(DivByNum) - 1)
    
    ElseIf Left(Base, 1) = "-" Then
    Negative = True
    Base = Right(Base, Len(Base) - 1)
    
End If

tempint = Len(Base)
tempstrC = Base
'I don't know exactly why I decide to put the
'base into a new string but it seamed to make
'things so much easier
For X = tempint - Len(DivByNum) + 1 To 1 Step -1
'This loop basicaly gets the string or whatever
'it is and manipulates it
    DoEvents
    If Int(Left(tempstrC, Len(DivByNum) + tempintB)) > Int(DivByNum) Then
        Do Until Int(Left(tempstrC, Len(DivByNum) + tempintB)) < (Int(DivByNum) * (10 ^ (X - 1)))
            FinalNum(X) = FinalNum(X) + 1
            tempstrC = Int(tempstrC) - (Int(DivByNum) * (10 ^ (X - 1)))
            
        Loop
        
    End If
    tempintB = tempintB + 1
Next

DivideNum = PutTogether(4)
If Negative = True Then
    DivideNum = "-" & DivideNum
End If

If Not tempstrC = "0" Then
    If LenDec1 > LenDec2 Then
        PutInPos = LenDec1 - LenDec2
        Else
        PutInPos = LenDec2 - LenDec1
    End If
    DivideNum = DivideNum & " - Remainder " & (Int(tempstrC) / (10 ^ PutInPos))
End If
'These parts just add the nesacary parts and also it gives the remainder.
End Function


[Ovu poruku je menjao krckoorascic dana 11.08.2006. u 03:23 GMT+1]
Seeking
 
Odgovor na temu

[es] :: Visual Basic 6 :: VB 6.0 i matematika

[ Pregleda: 1619 | Odgovora: 12 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.