I have looked for answers and I have shuffled around every variably, quotation mark, form reference, everything that I can think of to get this DLookup to work. Here's the background information on what I'm trying to do here:
PrimaryRouteID = short text data (key player in this lookup)
SignSumtxt & SqFtSumtxt = textboxes where I want my DLookup values to show (via changing the control source in VBA)
PrimaryRoadInventoryTotals = The query that has the pertinent information that I want
PrimaryRoadInventoryMaster = Form nested in Navigation form (main form to use)
The rest I'll explain here: I'm designing a DLookup function that finds a quantity on the PrimaryRoad InventoryTotals query using the PrimaryRouteID taken from a textbox on a form that is nested in a Navigation form. This DLookup functions within the form by itself, but I've been struggling to fix it to work within the Navigation form.
It's my understanding that since I have put the MasterForm in the NavForm, it is now nested in the NavSubform, and you have to reference values inside the NavSubform, not just the form that you're working in. I seem to have figured out the correct syntax (I think) to grab the value I want, but my DLookup still does not function like it needs to. In the version below, both textboxes that have DLookups assigned to them have #Name? errors. I cannot for the life of me figure out what to do!
The Code (separated for easier viewing):
Private Sub RouteSelectCombo_AfterUpdate()
SignSumtxt.ControlSource = DLookup("[TotalQuantity]", "[PrimaryRoadInventoryTotals]", "[PrimaryRoadInventoryTotals]![PrimaryRouteID] ='" & [Forms]![NavigationForm]![NavigationSubform].Form![PrimaryRouteIDtxt] & "'")
SqftSumtxt.ControlSource = DLookup("[TotalSqFt]", "[PrimaryRoadInventoryTotals]", "[PrimaryRoadInventoryTotals]![PrimaryRouteID] ='" & [Forms]![NavigationForm]![NavigationSubform].Form![PrimaryRouteIDtxt] & "'")
End Sub
One weird thing that I noticed, and what might be an indicator of what's wrong here, is that when I nest this code into a msgbox, it'll read "true" or "false." Don't know if that helps, but figured I'd mention it.
I appreciate it!
If you want to assign a value to a control, use the .Value property, not the .ControlSource property. The .ControlSource property takes a string control source, and that should start with = if you're using an expression.
If you actually want to assign the control source, you could either add "=" & at the start, but that's really bad design. The control source should not be variable.
What you probably should do:
Private Sub RouteSelectCombo_AfterUpdate()
SignSumtxt.Value= DLookup("[TotalQuantity]", "[PrimaryRoadInventoryTotals]", "[PrimaryRoadInventoryTotals]![PrimaryRouteID] ='" & [Forms]![NavigationForm]![NavigationSubform].Form![PrimaryRouteIDtxt] & "'")
SqftSumtxt.Value= DLookup("[TotalSqFt]", "[PrimaryRoadInventoryTotals]", "[PrimaryRoadInventoryTotals]![PrimaryRouteID] ='" & [Forms]![NavigationForm]![NavigationSubform].Form![PrimaryRouteIDtxt] & "'")
End Sub
If you actually want to use it as a control source:
Private Sub RouteSelectCombo_AfterUpdate()
SignSumtxt.ControlSource = "=DLookup(""[TotalQuantity]"", ""[PrimaryRoadInventoryTotals]"", ""[PrimaryRoadInventoryTotals]![PrimaryRouteID] ='"" & [Forms]![NavigationForm]![NavigationSubform].Form![PrimaryRouteIDtxt] & ""'"")"
SqftSumtxt.ControlSource = "=DLookup(""[TotalSqFt]"", ""[PrimaryRoadInventoryTotals]"", ""[PrimaryRoadInventoryTotals]![PrimaryRouteID] ='"" & [Forms]![NavigationForm]![NavigationSubform].Form![PrimaryRouteIDtxt] & ""'"")"
End Sub
I wanted to come back to this question and give some closure on the topic. While I wasn't successful in the methods presented here (and I'm sure I wasn't implementing them correctly), I ended up taking the route of simplicity (per Robert Harvey's suggestion) over forcing what I thought to be the best way to set up the Navigation form, and instead just make a form that has buttons which lead to the other forms that are to be used.
This way, I don't have to do any sort of crazy subform within a form within a nav form referencing, and I don't have a bunch of tabs on my Navigation form.
Thanks everyone for your help and answers!
Related
This question is an offshoot of: Localizing ObjectListView OLVColumn, impossible due to Empty Name property
For simplicity's sake, let's say my ObjectListView contains car information. User A wants to display only Make and Model columns. User B only wants to display Model and Year columns. These preferences would be saved to/loaded from an .ini file on the users' local machines.
I cannot loop through the columns of the ObjectListView and do if (col.Name == colNameFromIni) { col.Visible == true; } because the .Name property of every column is an empty string ("") and does not get serialized to the designer codebehind file. This never happens with any other Winforms control (Label, Button, etc.) They always get their .Name written to the designer codebehind.
In some sense, this is a flaw in Winforms itself, because OLVColumn inherits from System.Windows.Forms.ColumnHeader, and a traditional ListView has exactly the same problem. .Name is always an empty string for all columns.
I would like to patch our local build of ObjectListView.dll to force populate the .Name property, but I can't figure out how Winforms automagically knows the name of every control on the form. It somehow(?) knows the names of the OLVColumn objects since it can display them in the Edit Columns... dialog on the ObjectListView's context menu. I'm also a little fuzzy on where the best spot is to plug this in.
(Yes, per linked question at top I know that as a last resort, I can hardcode colXX.Name = "colXX"; for all columns in my source code, but future column additions are likely to get overlooked and a programmatic solution is much preferred.)
(See also: https://sourceforge.net/p/objectlistview/bugs/160/ : the ObjectListView author declared this a wont-fix so it is up to me (or us), I guess.)
As you point out, this is a bug which is not with the ObjectListView, but the underlying component. And a bug which is around since at least 2008! Therefore, I doubt it will ever be fixed by MS.
Actually, it is a problem with the Autogenerated code in the designer.
If you look at other components such as a button, then the autogenerated code adds a name such as this;
//
// button2
//
this.button2.Location = new System.Drawing.Point(458, 199);
this.button2.Name = "button2";
...
But for ColumnHeader (Listview) and OLVColumn (ObjectListView), then this is not done, so then you end up with this.
//
// olvColumn1
//
this.olvColumn1.AspectName = "Name";
this.olvColumn1.Text = "Name";
If you manually add the line
this.olvColumn1.Text = "olvColumn1";
Then the "problem" is solved.
Of course, you can't do this, because the designer will override the autogenerated code when you make any changes, and then you will lose these manually added lines. It is also not sustainable.
So I'm afraid you need to code around this with some kind of ugly solution. Some options are:
Use the Tag to store the name and compare against this.
Use the text instead of the name (not possible if you have multi
language support!)
Code the names column manually in the Constructor
Set the Text to be something like "ColName;ColText" and then in your
code separate these out.
I have done option 3 in the past, but only I was maintaining the code, so this was easy.
What you could do to ensure you don't have discrepancies is to add a check in your constructor to compare the actual number of columns with the number you expect (hard coded for), and throw an exception if they don't match. Also, not the best, but another way to highlight and reduce errors.
The workaround for this is to get the OLVColumns via reflection and set their column's Name property at runtime. Every OLVColumn is a form-level field, so just pick them out of the list returned by GetFields().
Dim allFieldInfos As FieldInfo() = GetType(FrmMain).GetFields(BindingFlags.NonPublic or BindingFlags.Instance)
For Each fi As FieldInfo In allFieldInfos
If fi.FieldType Is GetType(OLVColumn) Then
Dim instance As OLVColumn = fi.GetValue(Me)
For Each col As OLVColumn In fdlvMain.AllColumns
If ReferenceEquals(col, instance) Then
col.Name = fi.Name
End If
Next
End If
Next
I am working on an excel sheet, which collects data from a website. A few words about this website:
- it is independant from me, I can not change its struckture
- it should look like a table, but it is not. The structure is like this:
<h4>blabla</h4><span class="address">blabla</span><span class="state_x">blabla</span>
<h4>blabla</h4><span class="address">blabla</span><span class="state_x">blabla</span>
<h4>blabla</h4><span class="address">blabla</span><span class="state_y">blabla</span>
The trick is the "state_?" class, its name can change (but only the end of it).
What am I doing now?
- collect all the data into arrays
- of course I will get "state_x" and "state_y" arrays
- go through the arrays, and write everything to a sheet
The problem:
When I get to the "state_?" arrays, I already don't know, where its data came from.
The best would be to have only one "state" array, which can collect data from any "state_?" classes. Of course this code doesn't work, but to show the logic:
Dim state As Variant
Set state = ieApp.Document.getElementsByClassName("state_*")
How could this work? Any help is appreciated, please consider, that I am new in vba.
NEW INFOS
I have found some further help by analysing the source HTML code. Each row is nested in a <div class="listitem"> </div>. Is it possible to create an array, where each element is a complete "listitem" div, and with a for loop extract the data from these elements, as written above?
Each "listitem" div can contain only one "state_?" class. So this way I wouldn't loose the information, where the data comes from.
Try querySelectorAll with selector e.g. "*[class^='state_']" which should select all elements which have class name that starts with text state_. More about selectors here. HTH
Dim states As IHTMLDOMChildrenCollection
Set doc = ie.document
Set states = doc.querySelectorAll("*[class^='state_']")
If (Not states Is Nothing) Then
Dim i
For i = 0 To states.Length - 1
Debug.Print states(i).innerHTML
Next i
End If
Im trying to send some checkbox values as an array and then insert it to my database, but I can't get the array values into variables in my asp page?
I want to get the array values into variables kalnr0=arrayvalue0, kalnr1=arrayvalue1 etc…
I have this now: And it shows the alert(texten) that say its an array.
Im sending the form with ajax method="GET"
and the form field:
<input type="checkbox" name="kalendrar_id[]" value="<%=rs("kalendrar_id")%>">
and on my receiving asp page I have this:
Dim kalendrar_id
kalendrar_id=request.querystring("kalendrar_id[]")
kalitem = Split(kalendrar_id, ",")
japp=array(kalitem)
If IsArray(japp) then
For i = 0 To UBound(kalitem)
On Error resume next
Response.Write kalnr(i)=i
Next
texten= " is an array"
Else
texten= " not an array"
End If
So how do I get the array values into the below variables?
kalnr0=Cstr(kalitem(0))
kalnr1=Cstr(kalitem(1))
kalnr2=Cstr(kalitem(2))
kalnr3=Cstr(kalitem(3))
kalnr4=Cstr(kalitem(4))
I really need some help with this, thanks :-)
If I set kalendrar_id="1,2,3,4,5" then it works, so kalendrar_id=request.querystring("kalendrar_id[]") is not getting any value, or its the wrong value!?
And if I post the form the normal way, not with ajax then it works, so somehow the query string request.querystring("kalendrar_id[]") is wrong, could it be something with encoding?
SOLVED. I had to remove [ ] from the form field, not sure what else, have tried so many things ;-)
First off, if your question is how to put something like the following into a loop...
var1 = var(1)
var2 = var(2)
...
var5 = var(5)
... the answer is don't do that. :) ("Doctor, it hurts when I press here." "So don't press there.")
Second, you don't need to use both Split() and Array(). Split() already produces an array, so the second function isn't doing anything useful.
Third, I'm not sure why you're using square brackets in the field names. If you think they'll somehow magically make your form return an array, well, they won't. All they'll do is make some servers eat your form results. (Not all servers, which is why square brackets are allowed in form field names, but they're still not a good idea, especially with method="get".)
To debug an issue like yours, the first thing to try is to look at what the form is returning. With method="get", you could just look at the querystring in the address bar, but it's better to explicitly see what the server thinks it's getting:
Response.Write "fieldname=" & Request.Querystring("fieldname") & "<br>"
If that doesn't get you what you expect, then you need to make sure the form field is actually named what you think it is. If yes, the next step is to double-check that the form is getting filled out - i.e. is the reason it's not returning a value the fact that there's no value to return?
I am working on a very old visual basic project. I have to rewrite the load and save function of the project. Therefore I wanted to create an array of controls which have all relevant textboxes and checkboxes included. I want to iterate through that array to be able to save the data into a textfile or load from it.
I have looked on the internet of how you can define those arrays, but it doesn't seem to work for me. Maybe I am doing something wrong, cause I am not an expert in Visual Basic.
I have tried to make it work this way:
Dim tbList As TextBox = { Form1.Text1, Form1.Text3, _
Form1.Text10, Form1.Text11, Form1.Text12, Form1.Text13, _
Form2.Text1, Form2.Text3, Form2.Text4, Form2.Text5, _
Form2.Text10, Form2.Text11, Form2.Text12, Form2.Text13, _
Form3.Text1, Form3.Text3, Form3.Text4, Form3.Text5, _
Form3.Text10, Form3.Text11, Form3.Text12, Form3.Text13, _
Form3.Text17, Form3.Text18, Form3.Text19, Form3.Text20, _
Form4.Text1, _
Form5.Text1, Form5.Text2, Form5.Text3, _
Form6.Text2, _
Form7.Text2}
Or with a list:
Dim tbList As New List(Of Controls)
The thing is Visual Basic always tells me there are some kind of compiling issues. There is no real explantation for this issue in VB, so I am asking here.
Your code isn't compiling because it is vb.net code. It should go without saying (but I'll say it anyway) that vb6 and vb.net are not the same thing.
If you want to use an array, you will have to dimension the array with a number that is one less than your number of textboxes (if I counted correctly there are 32 in your example):
'// array is zero based so 0 to 31 = 32 items
Dim tbList(31) As TextBox
tbList(0) = Form1.Text1
tbList(1) = Form1.Text3
'//...I'll leave the rest as an exercise for the programmer
tbList(31) = Form7.Text2
Dim i As Integer
Dim tb As TextBox
'// To loop and work with each textbox
For i = 0 To UBound(tbList)
Set tb = tbList(i)
'// do something with tb
Next
An easier way to do it, however, is to work with a collection:
Dim tbList As New Collection
tbList.Add Form1.Text1
tbList.Add Form1.Text3
'//...I'll leave the rest as an exercise for the programmer
tbList.Add Form7.Text2
Dim tb As TextBox
'// To loop and work with each textbox
For Each tb In tbList
'// do something with tb
Next
Yes, you can use a collection if you want to go to the trouble. But an even easier way to work with it is to use VB6's (now obsolete) control array implementation. Most of us were disappointed when we found it was no longer available in .Net!
All you have to do to get control arrays in VB6 is create a bunch of controls with the same name. (They do have to be the same type of control; you can't make arrays of, say, text boxes and combo boxes.) Start with one text box, name it what you want, and copy it. You will be asked if you want to create a control array. Say yes, copy as many as you want. You will notice that the Index property is no longer blank, starting with 0 and incrementing from there. You will also notice that all of the event handlers have an "Index As Integer" argument to them. This way, you can use the same event handler for all of them, evaluating the Index argument to find out which member of your array is firing the event.
Here is the old doc for it. Microsoft makes it hard to find. :)
Above is a database that i am uploading to a hosting server to pull the data off of it to a website using .asp code in a HTML file. The sensors field gets the data using lookup from another table and can contain multiple values but these values are separated using a comma ",". I was wondering if there was a way either within the database or on the .asp page to get rid of the comma and sort them in a new paragraph or replace the "," with "< br/ >" between each of the sentences
NOTE CHANGE TO ORIGINAL QUESTION
The original question was in reference to ASP.NET. After providing a thorough answer it transpired that the author was actually using VBScript and Classic ASP. The final update to this answer reflects his change.
I have left my original answer just in case it helps someone else with the same issue as originally asked..
===================================
Replace won't be enough if you want to change any of the order; I.E alphabetically.
One way would be to put the Database string into a list, splitting it at the comma. you can then output this list in any order you want.
For example.
to Split into a list
List<string> myList = yourSensorsString.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
You can then order this however you see fit. Something like:
myList.Sort();
Then simply go through each of the items, like - where myLbl is perhaps a label control on your page
foreach ( str in myList) {
myLbl.Text += str + "<br />";
}
Or as separate paragraphs, maybe into a Literal
foreach ( str in myList) {
myLit.Text += "<p>" + str + "</p>";
}
Update
This code example above would be placed in your code-behind. You would get your sensors string from the database, and then split it into a list, then output to the HTML. No need to get your database to perform this sort of logic.
I have also assumed C# as you never mentioned what flavour of .net you're using.
Update 2
After looking at your fiddle, i edited it slightly to show where you can use this sort of code. Also converted my code to VB. Hope this helps. Can't put any more time into this... Fiddle Is Here
Update 3
The original question was for ASP.NET - as it turns out, it's actually Classic ASP the OP is asking about.
So split your string like this:
myList=Split(rsLogbook("FieldName"), ",")
for each str in myList
document.write(str & "<br />")
next
Other than that, I can't help any further - lot of time spent on this :)