Hello Everyone,

I have been given the task of rewriting a Visual RPG Shop Floor system in VB.Net.

Would anyone be able to advise me on how I can use an Array to lookup a date in VB.Net?

In RPG I would use the Lookup function %LookupGE to get the index of the date in the array,

but in VB.Net the search function only allows equal or exists.

The only solution I can think of is a Do loop with a date comparision.

I have included examples of the RPG and VB.Net

RPG example
1. Define the arrays
* Arrays
* ------
DDte S D Dim(16) Inz Ascend
DWQtP S 9S 0 Dim(16) Inz
DWVlP S 9S 2 Dim(16) Inz

2. Setup the Date array with sixteen weekending dates
// Load the array with dates
WkDate = %date(PaFoDate);
Index = 0;
Dou Index >= 16;
Index = Index + 1;
Dte(Index) = WkDate;
WkDate = WkDate + %Days(7);

3. Read the MRP file and get the index for the date in the array that is greater than or equal to the Required Date
Dou %eof(MrpPLvl5);
Read MrpPLvl5;
If not %eof(MrpPLvl5);
// Lookup and get the index for the Required Date
Index = %LookupGE(RReqDat:Dte);
If Index > 0;
WQtP(Index) = WQtP(Index) + RQtyRq;
WVlP(Index) = WVlP(Index) + (RQtyRq * (PrRelPrc / WkExcRt));

VB.Net example

Public Class Form1
Dim arrDate(15) As Date
Dim wkDate As Date
Dim Index As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Initialise date to today's date
txtCurrentDate.Text = DateTime.Now.ToString("d")
txtDate.Text = txtCurrentDate.Text
txtArrayIndex.Text = ""
wkDate = Date.Now.ToString("d")
' Get Day of the week
txtDayOfWeek.Text = wkDate.ToString("dddd")
Index = 0
Do While Index < 16
arrDate(Index) = wkDate
Index = Index + 1
wkDate = wkDate.AddDays(7)
End Sub

Private Sub btnGetIndex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetIndex.Click

' Checks if date is valid
If (IsDate(txtDate.Text)) Then
wkDate = txtDate.Text
'Get the index of the array Date greater than or equal to the entered date
Index = Array.IndexOf(arrDate, wkDate)
'if a date is not entered then this will display
MessageBox.Show("Please input a valid date in the format MM/DD/YY ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End If
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End Sub

End Class



This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].