I'm doing a visual studio 2010 project in VB.NET to import an ASCII file into a databae based on given fields in the ASCII file. Sometimes, there can be some optional fields missing from the ASCII file while importing.
How can I find out which property of a big class has not yet been assigned a value? Based on this, I want to show a form to request for the missing properties at run time!
Someone correct me if there is a faster way,
Dim myClassInstance As new MyClass();
If myClassInstance.SomeProperties is Nothing Then
'I'm null
End If
Do this for all properties that needs to be checked.
Related
I'm struggling to save the current value of an object (at least I think it's an object) in MS Project VBA.
Here's what I'm trying to do, save the value of my current header text.
dim a As String (or Variant/Object?)
a = Application.FilePageSetupHeader.Text.Value
This obviously doesn't work, but gets the point across.
The syntax for this is:
expression. FilePageSetupHeader( ** Name, ** Alignment, ** Text** )
with Name and Text being passed as a string.
If I get this to work, I'll also be interested in extracting the NormalType value from this object. Notice I'll have to specify the item:
GridlinesEditEx Item:=4, NormalType:=1
Any help would be appreciated!
FilePageSetupHeader is a method of the application object, not a property (see MSDN). The MS Project object model does not have a header object to interrogate, so unfortunately the headers (and footers) are write-only.
Ok.
So I am working on a project, irrelevant, and I have a bunch (8) of ComboBoxes (they are in DropDownList mode) and there is 8 save files. I have them being imported and converted to strings:
Using class2 As New StreamReader(path & "SaveData/classdata/classdata2.NIC")
Dim fdcount1 As String
fdcount = class2.ReadToEnd()
MessageBox.Show(fdcount1)
hr2choice.SelectedItem = fdcount1
End Using
I already tested this, and it seems to be working.
(Test code I used:)
MessageBox.Show(fdcount1)
and it showed the value ("DiVita")
Despite this, when I tried setting the ComboBox value to this, it did not seem to work.
The ComboBox does have this value in it, and if I try this, it works:
hr2choice.SelectedItem = "DiVita"
For whatever reasons though, it does not work when I try doing it directly from the string.
Thanks for any help with this!
Nic
To answer this, I have to assume that the data in the text file is formatted as one line for each piece of data.
There seems to be a couple of issues with your code. fdcount is just declared as a string where it should be an array to make it easier to access each line that is read from the file. fdcount1 has no relationship to fdcount - it is a completely separate entity, so the data in fdcount1 is coming from somewhere else.
Rather than the above code, It's easier to use this
Dim fdcount() As String
fdcount = File.ReadAllLines("SaveData/classdata/classdata2.NIC")
MessageBox.Show(fdcount(1))
Note that fdcount is declared as an Array of String. The 2nd line does all the opening, reading into the array, and closing of the file.
You can then access each element of the array as shown in the 3rd line.
I am developing an application, and as one of the steps, I need to have a set of information backed up to an SQL database.
I don't have any experience using SQL, and was hoping I could find a simple command that would just add a row with the information i'd needed... But I don't understand much of the information I've found for it. I've even had issues just using the snippet provided within Visual Studio.
I tried using the snippet for adding a row, and here's the code that's produced.
The reference to RDataSet.ArchivedIncidentsDataTable keeps giving me an error message telling me "object reference to non-shared object requires an object reference", which to me, is one of the least helpful error messages you could possibly receive. I don't understand what it means, or what I need to do in order to fix it.
Here is the code that I have, which is basically just the snippet that's provided:
Private Sub Save_SQLBackup_Info()
Dim newRow = CType(RDataSet.ArchivedIncidentsDataTable.NewRow(), RDataSet.ArchivedIncidentsRow)
newRow.CustomerID = "A124"
newRow.CompanyName = "Acme"
RDataSet.ArchivedIncidentsDataTable.Rows.Add(newRow)
End Sub
I'm not sure how filling in the fields for this small amount of code produced an error.
Also, after this segment of code is run, don't I have to run a command to update the database? The guides I'd been following online all referenced something like that, but I didn't understand the other parts of them.
I'm sure the problem i'm having is a matter of "You didn't declare X.", however I don't know much about SQL... If that's even what I'm using.
I would appreciate some guidance.
All I need to do is add a row to the database using a few fields from the form.
I have an online SQL server linked as a data object, and the dataset is titled RDataSet , the data table is titled ArchivedIncidentsDataTable.
The few guides I've found online reference different parts, like data adapters, that I don't have, and / or don't reference how they got to that part... I'm completely lost.
Is there any sort of one-line command I can run that will just shoot the information I'd like added to a row into this database? I don't understand why it has to be this complicated...
EDIT:
One of the answers was to drag an instance of the dataset onto the form.
After doing this, and trying to reference it, I'm now getting an error message telling me :
"Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
This message appears under the autocorrect options, and gives me the option to replace the dataset I added to the form, RDataSet1, with RDataset.
When hovering over the code "RDataSet1.ArchivedIncidentsDataTable.NewRow()", I still see the error message "Object Reference requires an object reference".
The message
object reference to non-shared object requires an object reference
means you're trying to access a member of a class like it's a shared member, but it's not, so you need an actually instance of that class (an object reference).
If you're using WinForms, you can just drag a RDataSet onto your Form, and it should generate a field in your Form called RDataSet1 or something like that (I asumme you used the DataSet Designer of Visual Studio).
Then use RDataSet1 (the object reference) instead of RDataSet (the type).
I have a report that needs to process the data that it get from SQL before show it.
For that, I have a custom code, and a Dictionary where I push all the processed data.
My problem is that if I save the dictionary in a report variable when I export the report to Word that variable seems to be cleaned.
What is the lifecycle of the reports variables? What is the most convenient way of saving an object during the report life.
Thanks!
I have been playing around with custom code for a about 6 weeks so I can answer some parts of the question of variable lifecycle in SSRS 2008 R2.
I have report that uses a Dictionary to store totals, allows me provide some specialist subtotals for financial stuff. I have something you can check (as I can't yet comment on things).
Have you declared the variable as 'shared', this is a custom code specific keyword that doesn't translate into VB.net. It ensures the variable lives to the next page, I tested this to Excel and word seemed to work fine transferring over the variable's data.
There is a trade off however under SSRS "report on demand" engine (on web, but not on BIDS) it holds the variable and doesn't garbage collect until the cache itself is cleared. I wrote some more custom code to indicate when my parameters changed and clears the variable.
Code;
Public Shared Dim Totals As New System.Collections.Generic.Dictionary(Of String, Decimal)
Public Function WipeKeys() as Decimal 'Clear Data from Dictionary (this will clear the cached object as well)
Totals.Clear()
Return 0D
End Function
I will also to recommend overwrite the key where ever possible to ensure reduction of addition loops.
Regards,
I'm trying to create an import program from CSV.
My code is
csv = New CsvReader(New StreamReader("CSVFileLocation"), True)
Dim fieldCount As Integer = csv.FieldCount
The error message "An item with the same key has already been added." on the second line.
If I changed "HasReaders" to "False", there's no such error. But, I'm not able to get the Headers.
Could somebody help me on this, please?
FYI: I'm using Visual Studio 2010 version.
Regards,
Richard
Check that your CSV file may have duplicate column names, or multiple empty cells, in the header row?
If that's the case, try to loop through your csv object, and try rename the headers in code before calling the property FieldCount.
My guess is that the CsvReader class is going through the first row adding strings to a dictionary, and the header row has two cells with the same value (so two identically named fields). Take a look at your data and see if this is the case. Alternately, if you have access to the source code for CsvReader, you could have it handle this case by naming the second field something slightly different (e.g., by appending a "1" onto the end of its name).