Error When Trying To Draw On The PictureBox - vb.net

I have this code. and this code works on button click.
X1picG00 = Double.Parse(XstrG00) * DrawScale
Y1picG00 = PictureBox1.Height - Double.Parse(YstrG00) * DrawScale
X2picG00 = Double.Parse(XendG00) * DrawScale
Y2picG00 = PictureBox1.Height - Double.Parse(YendG00) * DrawScale
X1picG00 = X1picG00 * Math.Cos(theta) - Y1picG00 * Math.Sin(theta)
Y1picG00 = X1picG00 * Math.Sin(theta) + Y1picG00 * Math.Cos(theta)
X2picG00 = X2picG00 * Math.Cos(theta) - Y2picG00 * Math.Sin(theta)
Y2picG00 = X2picG00 * Math.Sin(theta) + Y2picG00 * Math.Cos(theta)
PictureBox1.CreateGraphics().DrawLine(Pens.White, Int(X2picG00 + PicBorderX), Int(Y2picG00 + PicBorderY), Int(X1picG00 + PicBorderX), Int(Y1picG00 + PicBorderY))
When the program reaches this code:
PictureBox1.CreateGraphics().DrawLine(Pens.White, Int(X2picG00 + PicBorderX), Int(Y2picG00 + PicBorderY), Int(X1picG00 + PicBorderX), Int(Y1picG00 + PicBorderY))
it shows me this error:
An unhandled exception of type 'System.Reflection.AmbiguousMatchException' occurred in Microsoft.VisualBasic.dll
Additional information: Overload resolution failed because no Public 'DrawLine' can be called without a narrowing conversion:
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)':
Argument matching parameter 'x1' narrows from 'Double' to 'Integer'.
Argument matching parameter 'y1' narrows from 'Double' to 'Integer'.
Argument matching parameter 'x2' narrows from 'Double' to 'Integer'.
Argument matching parameter 'y2' narrows from 'Double' to 'Integer'.
'Public Sub DrawLine(pen As System.Drawing.Pen, x1 As Single, y1 As Single, x2 As Single, y2 As Single)':
Argument matching parameter 'x1' narrows from 'Double' to 'Single'.
Argument matching parameter 'y1' narrows from 'Double' to 'Single'.
Argument matching parameter 'x2' narrows from 'Double' to 'Single'.
Argument matching parameter 'y2' narrows from 'Double' to 'Single'.
I can't understand why this error happened and what is it.
What is this error and how can I fix it ?
Additional information: The variables XstrG00 and XendG00 and YstrG00 and YendG00 have a value and their values Depend on values of TextBoxes.
And the value of DrawScale variable is 0.7.
And the value of PicBorderX variable is 70.
and the value of PicBorderY variable is 10.

Related

Error message for dividing by zero when variable in 0 is = 1

The program keep saying that there is a division by zero in Term = (-1 ^ (i - 1)) * (X ^ (2 * (i - 1))) / M even though M was set to equal 1 before this calculation took place. I have tried change the value of M but it continuously keeps giving the division by 0 error message. This program is supposed to calculate sin(x) without using the built in function. Any insight towards this is very much appriciated.
Option Explicit
Sub MainPrg()
Dim X As Single, LastTerm As Long, M As Double, Term As Long, i As
Single, _
ActVal As Single, Sum As Long
'
'
X = InputBox("Please input the angle in degrees")
X = X * (3.14159 / 180)
LastTerm = InputBox("Please enter the largest value for the last
term in the series")
ActVal = Sin(X)
Call SinCalc(LastTerm, M, i, Term, Sum, X)
MsgBox ("The calculated value is " & Sum & " And the actual value
is " & ActVal)
End Sub
Function Fact(ByVal i As Single, ByRef M As Double)
M = M * (2 * (i - 1))
End Function
Sub SinCalc(ByVal LastTerm As Double, ByVal M As Double, ByVal i As
Single, _
ByRef Term As Long, ByRef Sum As Long, ByVal X As Single)
i = 1
M = 1
Sum = 0
Do
Term = (-1 ^ (i - 1)) * (X ^ (2 * (i - 1))) / M
Sum = Sum + Term
If (Abs(Term) < LastTerm) Then Exit Do
i = i + 1
Call Fact (i,M)
Loop
End Sub
Your line with the issue
Term = (-1 ^ (i - 1)) * (X ^ (2 * (i - 1))) / M
is inside a loop so even if at the beginning M is equal to 1 it can become equal to 0 after (this happens during the fact function)

How can I fix the Run-time error '5': invalid procedure call or argument

How can I fix the
Run-time error '5': invalid procedure call or argument
I have a this line in my code: Betac = ((t - t0) / (Betah(h, RH, alfa3) + (t - t0))) ^ 0.3.
It runs correctly when I enter the h parameter by myself, but when I input it by variable VBA shows this error.
please help!
' ????? if I input h here runs correctly
' but when input it in the function argument vba gives run time error '5'
h = 777
RH = Cells(26, 11)
Betafcm = (16.8 / Sqr(fcm))
Betat0 = 1 / (0.1 + t0 ^ 0.2)
alfa1 = (35 / fcm) ^ 0.7
alfa2 = (35 / fcm) ^ 0.2
alfa3 = (35 / fcm) ^ 0.5
Betac = ((t - t0) / (Betah(h, RH, alfa3) + (t - t0))) ^ 0.3

String to CRC32 as 4 bytes and LZMA1 conversion in ABAP

I need to for QR code payBySquare in Slovak republic convert Array to string and make CRC32 HASH. Afther that I need comprime HASH by LZMA1 . I hope my code is ok to CRC32 But I cannot find how to make comprimation by LZMA1.
method GENERATE_QR_STRING_FOR_SR.
DATA: lw_string TYPE STRING,
lw_wrbtr_s TYPE STRING,
lo_crc TYPE REF TO IF_SCV_CRC_SERVICES,
lo_crc_hash TYPE REF TO IF_SCV_CRC32.
LW_WRBTR_S = me->WRBTR.
CONCATENATE 'true'
LW_WRBTR_S "
me->WAERS "Currency
'20170101' "'Date'
me->VAR_SYMB "Variabile Symbol
me->CON_SYMB "Constant Symbol
me->SPE_SYMB "Specific Symbol
''
me->INF_FOR_BE "Information for benef..
'1'
me->IBAN "Iban
me->SWIFT "SWIFT
'0'
'0'
INTO lw_string SEPARATED BY ' '.
CONCATENATE '' '1' lw_string INTO lw_string SEPARATED BY ' '.
DATA:
ld_CONTENT TYPE XSTRING ,
ld_CRC32 TYPE I.
" ld_CONTENT = "<Populate with value>
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = LW_STRING
* MIMETYPE = ' '
* ENCODING =
IMPORTING
BUFFER = LD_CONTENT
* EXCEPTIONS
* FAILED = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
CALL METHOD CL_UJF_ZIP=>CRC32( EXPORTING CONTENT = ld_CONTENT RECEIVING CRC32 = ld_CRC32 ).
"ld_CRC32 = CL_RSBPCF_ZIP=>CRC32( EXPORTING CONTENT = ld_CONTENT ).

Apparent incorrect value from variable definition?

New to VBA and lousy at it, so please be gentle!
I have the following code which gives the Long type variable "EIa" a value. I was getting a bunch of odd results later down the code so I put in some Debug.Print lines to find my issue and notice that when I Debug.Print the variable EIa, I get 0 but if I Debug.Print EXACTLY the expression that defines EIa, I get the expected value. Code below, any ideas?
'Calculate mA1:
'****************************************************************************************************
EIa = Etimber * ImatA / (Etimber * (ImatA + ImatB + ImatC + ImatD))
Debug.Print "EIa = "; EIa
Debug.Print "EIa = "; Etimber * ImatA / (Etimber * (ImatA + ImatB + ImatC + ImatD))
mA1 = 12 * 0.5 * (q1PSF * EIa) * bMat * LcantiA ^ 2 '12 puts this into lb-in
If LmatSymA = 0 Then
fbA1 = 0
Else
fbA1 = (mA1 * (0.5 * tMatA) / ImatA)
End If
The result of the expression is a kind of fractional, floating point number, but since you defined EIa as Long (a large integer), it gets truncated to zero upon assignment.
See Visual Basic Data Types.

Getting NaN for a double datatype

I am trying to run some mathematical formula which has large values, so I am using the Double datatype. But still I am getting the answer as NaN if I input large values. So how can I solve this?
For example, if I pass Varx=3 and countx=1230 I get the result as NaN.
Public Function EulerForPro(ByVal Varx As Integer, ByVal Countx As Integer) As Double
Dim Result1 As Double = 1
Dim Result2 As Double = Varx
Dim Result As Double = 0
For i = 1 To Countx
Result1 = Result1 + (Math.Pow(-1, i) * Math.Pow(Varx, (2 * i)) / factx(2 * i))
Next
For i = 1 To Countx
Result2 = Result2 + (Math.Pow(-1, i) * Math.Pow(Varx, ((2 * i) + 1)) / factx((2 * i) + 1))
Next
Result = Result1 + Result2
Label2.Text = Result1
Label3.Text = Result2
Label4.Text = Result
End Function
Use the logarithm of the results. It is standard practice for large numbers.
So instead of multiplying a*b (which causes overflow), use
Y = log(a) + log(b)
You could try using the Decimal data type instead. It can hold an integer value of approximately 7,9 x 10^28 (the exact number is 2^96 - 1, since it can use 96 bits of its 128 for storing the integer part of a value). However, it's a complex data type and you should carefully consider how to use it in your code. Not all implicit conversions work, especially when using Double.
See MSDN on decimal for exact specifications of Decimal.