Store variable using RowTagAt

Hi! It’s me :smiley:

I’d like to confirm please if my record set looks like this:

// Get the values from the current row
Dim value0 As String = rs.Field("custID").StringValue
Dim value1 As String = rs.Field("custCompany").StringValue
Dim value2 As String = rs.Field("custName").StringValue
Dim value3 As String = rs.Field("custTel").StringValue
Dim value4 As String = rs.Field("custMob").StringValue
Dim value5 As String = rs.Field("custEmail").StringValue

// Add a new row to the list box with the retrieved values
CustActiveListBox.AddRow(value0, value1, value2, value3, value4, value5)

Is this the correct way to store the custID as a variable?

//Store the custID so it can be used in the DoublePressed event
CustActiveListBox.RowTagAt(CustActiveListBox.RowCount - 1) = value0

If you guys answer; yes. Then I have a follow up question

Thank you
zac

oh, it took me a long time to put that together. :frowning:
I should point out that the actual recordset does work.

It’s certainly one way to do it. Although I notice that you’re not setting the encoding for any of those strings. What’s the problem?

I read somewhere that the encoding for sqlite defaulted and that it was best left alone unless absolutely necessary. however i’m obviously open to suggestions.

so i came here to ask one question but it turns out that even the bit that i thought ‘ok’ isnt ‘ok’

Sure. You can put anything you want in the RowTag (and CellTags). LastRowIndex would be more concise than RowCount-1.

1 Like

What’s wrong with it?

2 Likes

thank you. Can lastRowIndex be used in a loop though?

so anyway, my follow up question is. Assuming I have stored the custID variable correctly. How can put that variable into a DoublePressed event?
Basically the user double clicks a row of data the custID needs to be used and passed to my method which holds a sql query. Sorry if that sounds like gibberish

In the double-click event:

Dim xValue, yValue, row, column As Integer
xValue = System.MouseX - Me.Left - Self.Left // Calculate current mouse position relative to top left of ListBox

yValue = System.MouseY - Me.Top - Self.Top // Calculate current mouse position relative to top of ListBox.

row = Me.RowFromXY(xValue, yValue)

YourMethod(me.RowTagAt(row))

thank you. Yes this is the coordinate method i was reading about. It sounded complicated!
So with your example…
Dim xValue, yValue, row, column As Integer (the error says this is an unused variable)

and if I change this line YourMethod(me.RowTagAt(row)) to be:
ShowEditCustomer(me.RowTagAt(row))

it says that ShowEditCustomer does not exist. But obviously it does exist. These are the kind of problems that I come across and don’t understand.

  1. Not an error, just a warning that you declare column but don’t then use it.

  2. What is ShowEditCustomer and where is it relative to this listbox?

Hi Tim,

2, ShowEditCustomer is a method of the EditCustomer window. The ShowEditCustomer method holds the sql query which pulls the customer data and then I specify which bits of data goes in which text fields.

Then you probably want:

Self.ShowEditCustomer (me.RowTagAt(row))

assuming that your listbox is in that window. And the method should have public scope.

hmm, no the listbox which is called CustActiveListBox is actually on window1
but yes the ShowEditCustomer method is public

so with this in mind would i change the ‘self’ to ‘window1’ ?

Try that, but why does the method not belong to the window where it will be used?

1 Like

maybe i’m explaining it incorrectly.

  • window1 shows a list box full of customers
  • user double clicks a row of data which opens a new window
  • that new window has the method.

if this is a silly way of trying to do something i’m all ears :smiley:

You should be passing, to the new window, the minimum of data needed to do the work there, in this case the custID from the listbox. Then the new window should do all the work and you should call that method there.

On all my similar windows I have a method called winShow, such as this (adapted to your situation) called thus from the double-pressed code:

otherwindow.winshow (custid)

and then winshow looks like:

localcustid = custid
me.show ()

localcustid is a property of otherwindow and is used to store the paramter passed to the window. You can extend that easily enough for more parameters. That way everything is local to where it is used.

When that window has finished you can hide it.

1 Like

yes! this is what i have been attempting to do. I’m glad you’ve just written that. But this refers back to my original question above… I’m not convinced that I am storing the custID variable correctly. because all I ever seem to get is: custID does not exist.

so i have been attempting to store the custID with:

//Store the custID so it can be used in the DoublePressed event
CustActiveListBox.RowTagAt(CustActiveListBox.RowCount - 1) = value0

It has been suggested here that it would be better to use LastRowIndex instead of RowCount

Well using lastrowindex saves the subtraction.

Actually it would probably be:

otherwindow.winshow (me.RowTagAt(row))

wouldn’t yiou say, as that is where the relevant value is.

1 Like

would this still be contained within the loop of the list box?

so in here:

// The loop through
While Not rs.EOF
  
  // Get the values from the current row
  Dim value0 As String = rs.Field("custID").StringValue
  Dim value1 As String = rs.Field("custCompany").StringValue
  Dim value2 As String = rs.Field("custName").StringValue
  Dim value3 As String = rs.Field("custTel").StringValue
  Dim value4 As String = rs.Field("custMob").StringValue
  Dim value5 As String = rs.Field("custEmail").StringValue
  
  // Add a new row to the list box with the retrieved values
  CustActiveListBox.AddRow(value0, value1, value2, value3, value4, value5)
  
//in here?????
  
  // next row
  rs.MoveNext
Wend
rs.Close

Yes, step one is populating the listbox and the rowtags, then in the double-pressed event you get hold of the relevant custid value and pass it to the other window for processing.