condition is satisfied but it doesn't run the codes - vb.net

If (need_1a.Text <= ava_4a.Text) And (need_1b.Text <= ava_4b.Text) And (need_1c.Text <= ava_4c.Text) Then
ava_5a.Text = Convert.ToInt32(ava_4a.Text) - Convert.ToInt32(need_1a.Text) + Convert.ToInt32(max_1a.Text)
ava_5b.Text = Convert.ToInt32(ava_4b.Text) - Convert.ToInt32(need_1b.Text) + Convert.ToInt32(max_1b.Text)
ava_5c.Text = Convert.ToInt32(ava_4c.Text) - Convert.ToInt32(need_1c.Text) + Convert.ToInt32(max_1c.Text)
need1 = 4
ElseIf (need_5a.Text <= ava_4a.Text) And (need_5b.Text <= ava_4b.Text) And (need_5c.Text <= ava_4c.Text) Then
ava_5a.Text = Convert.ToInt32(ava_4a.Text) - Convert.ToInt32(need_5a.Text) + Convert.ToInt32(max_5a.Text)
ava_5b.Text = Convert.ToInt32(ava_4b.Text) - Convert.ToInt32(need_5b.Text) + Convert.ToInt32(max_5b.Text)
ava_5c.Text = Convert.ToInt32(ava_4c.Text) - Convert.ToInt32(need_5c.Text) + Convert.ToInt32(max_5c.Text)
need5 = 4
End If
i have this code, the first condition is satisfied but it doesn't run the code.

Use Val ()
Without val() its a string comparision.
If (Val(need_1a.Text) <= Val(ava_4a.Text)) And (Val(need_1b.Text) <= Val(ava_4b.Tex)t)
And (Val(need_1c.Text) <= Valava_4c.Text)) Then
ava_5a.Text = Convert.ToInt32(ava_4a.Text) - Convert.ToInt32(need_1a.Text) +
Convert.ToInt32(max_1a.Text)
ava_5b.Text = Convert.ToInt32(ava_4b.Text) - Convert.ToInt32(need_1b.Text) +
Convert.ToInt32(max_1b.Text)
ava_5c.Text = Convert.ToInt32(ava_4c.Text) - Convert.ToInt32(need_1c.Text) +
Convert.ToInt32(max_1c.Text)
need1 = 4
ElseIf (Val(need_5a.Text) <= Val(ava_4a.Text)) And (Val(need_5b.Text) <=
Val(ava_4b.Text)) And (Val(need_5c.Text) <= Val(ava_4c.Text)) Then
ava_5a.Text = Convert.ToInt32(ava_4a.Text) - Convert.ToInt32(need_5a.Text) +
Convert.ToInt32(max_5a.Text)
ava_5b.Text = Convert.ToInt32(ava_4b.Text) - Convert.ToInt32(need_5b.Text) +
Convert.ToInt32(max_5b.Text)
ava_5c.Text = Convert.ToInt32(ava_4c.Text) - Convert.ToInt32(need_5c.Text) +
Convert.ToInt32(max_5c.Text)
need5 = 4
End If

Related

Write Select Case statement in VBA more briefly

Is it possible to write the following code in VBA Excel 2016 more briefly?
Select Case NemberOfProduct(i)
Case 1
CounterPlot(1) = CounterPlot(1) + 1
SumPureRate(1) = SumPureRate(1) + H(i)
Case 2
CounterPlot(2) = CounterPlot(2) + 1
SumPureRate(2) = SumPureRate(2) + H(i)
Case 3
CounterPlot(3) = CounterPlot(3) + 1
SumPureRate(3) = SumPureRate(3) + H(i)
.
.
Case 12
CounterPlot(12) = CounterPlot(12) + 1
SumPureRate(12) = SumPureRate(12) + H(i)
End Select
You could either manualy use NemberOfProduct(i) expresion as value.
So your whole select case could be replaced with
CounterPlot(NemberOfProduct(i)) = CounterPlot(NemberOfProduct(i)) + 1
SumPureRate(NemberOfProduct(i)) = SumPureRate(NemberOfProduct(i)) + H(i)
Or even more simplify it by storing NemberOfProduct(i) inside variable and then use it.
Dim n as Integer
n = NemberOfProduct(i)
CounterPlot(n) = CounterPlot(n) + 1
SumPureRate(n) = SumPureRate(n) + H(i)

How to improve the given line of code while filtering pandas dataframe?

The below line of code was to filter a dataframe. I would like to know how to improve this line of code
T1_df = df2[((df2['Azimuth'] > (df2['Sim_Az'] - 1)) & (df2['Azimuth'] < (df2['Sim_Az'] + 1)))]
T1_df = T1_df[((T1_df['Elevation'] > (T1_df['Sim_EL'] - 1)) & (T1_df['Elevation'] < (T1_df['Sim_EL'] + 1)))]
T1_df = T1_df[((T1_df['RadVel'] > (T1_df['Sim_velocity'] - 1)) & (T1_df['RadVel'] < (T1_df['Sim_velocity'] + 1)))]
T1_df = T1_df[((T1_df['Cross_Sec'] > (T1_df['Sim_rcs'] - 1)) & (T1_df['Cross_Sec'] < (T1_df['Sim_rcs'] + 1)))]
T1_df = T1_df[((T1_df['Distance'] > (T1_df['Sim_distance'] - 1)) & (T1_df['Distance'] < (T1_df['Sim_distance'] + 1)))]

Import data into sql developer from .csv file

I have to import some data in my Shipment table from .csv file,but i have problem with imorting DATE.
Here is you can see my generator:
class Shipment extends Generator
{
private String snd_time;
private String dliv_time;
private int deliv_id;
private int post_id;
int d, m, y, rnd;
public Shipment() throws FileNotFoundException, Exception
{
PrintWriter wr = new PrintWriter("ShipmentData.csv");
for(int i = 1; i < 100001; i++){
m = 1 + r.nextInt(12);
y = 2005 + r.nextInt(16);
if(m == 1 || m == 3 || m ==5 || m ==7 || m ==8 || m ==10 || m ==12)
d = 1+r.nextInt(31);
if(m == 4 || m == 6 || m == 9 || m == 11)
d = 1 + r.nextInt(30);
if((y % 4 == 0) && m == 2)
d = 1 + r.nextInt(29);
if((y % 4 ) != 0 && m == 2 )
d = 1 + r.nextInt(28);
if(m >= 10 && d >= 10)
snd_time = Integer.toString(d) + "/" + Integer.toString(m) + "/" + Integer.toString(y);
if(m < 10 && d < 10)
snd_time = "0" + Integer.toString(d) + "/" + "0" + Integer.toString(m) + "/" + Integer.toString(y);
if(d < 10 && m >= 10)
snd_time = "0" + Integer.toString(d) + "/" + Integer.toString(m) + "/" +Integer.toString(y);
if(m < 10 && d >= 10)
snd_time = Integer.toString(d) + "/" + "0" + Integer.toString(m) + "/" + Integer.toString(y);
rnd = 1 + r.nextInt(7);
if(m == 1 || m == 3 || m ==5 || m ==7 || m ==8 || m ==10 || m ==12)
{
if((d + rnd) > 31 ) {
d = (d + rnd) - 31;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 31)
d += rnd;
}
if(m == 4 || m == 6 || m == 9 || m == 11)
{
if((d + rnd) > 30) {
d = (d + rnd) - 30;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 30)
d += rnd;
}
if((y % 4 == 0) && m == 2)
{
if((d + rnd) > 29) {
d = (d + rnd) - 29;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 29)
d += rnd;
}
if((y % 4 ) != 0 && m == 2 )
{
if((d + rnd) > 28) {
d = (d + rnd) - 28;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 28)
d += rnd;
}
if(m >= 10 && d >= 10)
dliv_time = Integer.toString(d) + "/" + Integer.toString(m) + "/" + Integer.toString(y);
if(m < 10 && d < 10)
dliv_time = "0" + Integer.toString(d) + "/" /*+ "0"*/ + Integer.toString(m) + "/" + Integer.toString(y);
if(d < 10 && m >= 10)
dliv_time = "0" + Integer.toString(d) + "/" + Integer.toString(m) + "/" +Integer.toString(y);
if(m < 10 && d >= 10)
dliv_time = Integer.toString(d) + "/" + "0" + Integer.toString(m) + "/" + Integer.toString(y);
deliv_id = 1 + r.nextInt(100000);
post_id = 1 + r.nextInt(100000);
wr.println(i + "," + this.snd_time + "," + this.dliv_time + "," + this.deliv_id + "," + this.post_id );
}
wr.close();
}
}
Here is my ctl file:
LOAD DATA
INFILE 'D:\databaseProject\Data\ShipmentData.csv'
INSERT INTO TABLE shipment
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
id,
send_time,
deliv_time DATE "dd/mm/yyyy",
delivery_id DATE "dd/mm/yyyy",
post_id
)
but when i load this ctl file i get this error
Record 4: Rejected - Error on table SHIPMENT, column SEND_TIME.
ORA-01843: not a valid month
I've tried to write my date without 0, but it still doesn't work and i cannot find a solution for my problem

Type Mismatch Array Position Compare Vba

I don't understand why I cannot compare an array in VBA. I created an array that starts 0 1 2 3. I added a comparison due to subscript errors trying to compare 0 to 0 - 1 so it can only start comparisons at 1 and continue. Now I'm receiving a type Mismatch 13 and I can't figure out why the data type is different/not working. I'm guessing i in a for loop is not considered an int or something?
It fails at CoordinatesArray(i) = CoordinatesArray(i-1)
Code:
For i = 0 To NumLines - 1
coordx1 = (vLines(12 * i + 6))
coordy1 = (vLines(12 * i + 7))
coordz1 = (vLines(12 * i + 8))
CoordinatesArray(i) = Array(coordx1, coordy1, coordz1)
If i > 0 Then
If CoordinatesArray(i) = CoordinatesArray(i - 1) Then
coordx1 = (vLines(7))
You will need to compare each value in the jagged array separately:
For i = 0 To NumLines - 1
coordx1 = (vLines(12 * i + 6))
coordy1 = (vLines(12 * i + 7))
coordz1 = (vLines(12 * i + 8))
CoordinatesArray(i) = Array(coordx1, coordy1, coordz1)
If i > 0 Then
If CoordinatesArray(i)(1) = CoordinatesArray(i - 1)(1) And _
CoordinatesArray(i)(2) = CoordinatesArray(i - 1)(2) And _
CoordinatesArray(i)(3) = CoordinatesArray(i - 1)(3) Then
coordx1 = (vLines(7))

Visual basic loop without freezing program?

I made a loop below to make a monster move around in my game, when the loops runs once the whole game freezes... any ideas to make the loop repeat every 5 seconds?
Randomize()
Dim value As Integer = CInt(Int((4 * Rnd()) + 1))
Do
If value = 1 Then
If Me.mob2.Location.X < 750 Then
Me.mob2.Location = New Point(Me.mob2.Location.X + 1, Me.mob2.Location.Y)
End If
ElseIf value = 2 Then
If Me.mob2.Location.Y < 549 Then
Me.mob2.Location = New Point(Me.mob2.Location.X, Me.mob2.Location.Y + 1)
End If
ElseIf value = 3 Then
If Me.mob2.Location.X > 12 Then
Me.mob2.Location = New Point(Me.mob2.Location.X - 1, Me.mob2.Location.Y)
End If
ElseIf value = 4 Then
If Me.mob2.Location.X < 750 Then
Me.mob2.Location = New Point(Me.mob2.Location.X + 1, Me.mob2.Location.Y)
End If
End If
Loop
Timer That doesn't work:
Private Sub Timer()
' Timer.interval = 1000
End Sub
Not a good solution but this will help you to understand the problem
the problem in that your screen is not refreshing try this:
Do
application.doevents() '' so each time it loops it will refresh your screen
If value = 1 Then
If Me.mob2.Location.X < 750 Then
Me.mob2.Location = New Point(Me.mob2.Location.X + 1, Me.mob2.Location.Y)
End If
ElseIf value = 2 Then
If Me.mob2.Location.Y < 549 Then
Me.mob2.Location = New Point(Me.mob2.Location.X, Me.mob2.Location.Y + 1)
End If
ElseIf value = 3 Then
If Me.mob2.Location.X > 12 Then
Me.mob2.Location = New Point(Me.mob2.Location.X - 1, Me.mob2.Location.Y)
End If
ElseIf value = 4 Then
If Me.mob2.Location.X < 750 Then
Me.mob2.Location = New Point(Me.mob2.Location.X + 1, Me.mob2.Location.Y)
End If
End If
Loop