|
|
yah! I know how many inputs are there in the file. Infact, its a formatted file i.e place for each variable is defined. for example, sequence of vaiable will be a,b,c,d in first line and e,f,g in second and h, i, j in third and so on.
Thanks.
amanjot
|
|
|
|
|
Hi Amanjot;
Here is one way to do it.
' Array to hold each number in the file
Dim intArray(0) As Integer
' Line of numers read from file
Dim inputText As String
' String to hold each value from input line
Dim splitText(20) As String
' Index into integer array
Dim index As Integer = 0
' Size of integer array holding values
Dim arraySize As Integer = -1
Dim reader As StreamReader = New StreamReader("c:\temp\integerfile.txt")
Do
' Read a line of text from file
inputText = reader.ReadLine
' Parse the line of integers
splitText = inputText.Split(" ")
' Calculate the size need for new values
arraySize += splitText.Length
' Resize the array to hold new values
ReDim Preserve intArray(arraySize)
' Put each value into a unique variable
For Each numberString As String In splitText
intArray(index) = CInt(numberString)
index += 1
Next
' ChecK to see if there are any more input
Loop Until reader.Peek = -1
....
reader.Close()
I hope that this was of some help
-Fernando
|
|
|
|
|
Text file connection via Adodc. I can add new record
How do I delete Record from it.I get error if try to use
FlatFile.Recordset.Delete
Error message I get is
Microsoft ODBC Text Driver Deleting data in a linked table is not supported by this ISAM
Is There Any other way I can delete the Record?
|
|
|
|
|
I've never use the Text driver for anything, but it would appear that deleting a record is not supported. You'd probably ahve to read the entire text file, then re-write it, skipping the record(s) that you want to delete.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How can I read a file from a web site. Let's say that the file is at http://www.thecodeproject.com/file.txt.
Thanks,
Martin
|
|
|
|
|
What your looking for is the HttpWebRequest[^] class.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
My pc is stand by how to wake up using visual Basic Program without moving mouse or pressing Keys.
|
|
|
|
|
Considering the process is not running in Standby mode, no, you can't wake up the machine from code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for Reply. Then If it possible to turn the computer in sleep and wake up mode using Viusal Basic Program. If yes, Please tell me How.
|
|
|
|
|
You can puit the system to sleep and setup a timer to schedule a wakeup. Not a VB Timer control, though! This is a waitable timer object otherwise known as a synchronization object. You're lost aren't you...?
Power is not as simple as calling a function called SystemSleep, or something like that. You can learn about how Windows and ACPI and APM works together to manage power. This is going to involve calling into the Win32 API and declaring a bunch of structures to get this to work. If your not skilled in this, you're going to have a VERY difficult time.
The docs for the Power Management API starts here[^]. I don't have any example code and no time to write any either. I don't even have a copy of VB6 anymore...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm looking for some guidance... I am trying to create a control array of combo boxes, and populate the list for each combo box with the same data from the same file. I would expect the syntax to be something like:
formName.comboName(comboIndex).AddName stringSomething
VB doesn't seem to like using AddName with an index. I have also tried using .Item without success. Does anyone have an example of how to successfully accomplish this?
Thanks!
|
|
|
|
|
I was unable to find the .AddName method you mention for the ComboBox Object, but here's an example that will hopefully help you:
'Declare control array
Dim ctrlArray(2) As Control
'Initialize control objects
For i As Integer = 0 To 2
ctrlArray(i) = New ComboBox
Next
'Declare and initialize an array of strings
Dim textItems() As String = {"Choice 1", "Choice 2", "Choice 3", "Choice 4"}
'Add each string as an item to each combobox in control array
For Each ctrl As ComboBox In ctrlArray
For Each text As String In textItems
ctrl.Items.Add(text)
Next
Next
Given the formName.comboName(comboIndex).AddName stringSomething statement in your post, you might find this useful, too: (this part is written on the fly, I have not run it through the debugger, but it should be good to go)
'Declare and initialize some text items
Dim textItems() As String = {"Choice 1", "Choice 2", "Choice 3", "Choice 4"}
'Look at each control on the form
For Each ctrl as Control in formName.controls
'If the control is a ComboBox
If ctrl.Type Is GetType(ComboBox) then
'Then add the text items to it.
For Each text As String In textItems
ctrl.Items.Add(text)
Next
End If
Next
|
|
|
|
|
I messed up the original post -- I meant AddItem, not AddName.
Thanks very much for your response. Your examples are very helpful, but raise a "true VB newbie" question.
Do I need to specifically create the control array (as you have done with Dim ctrlArray in the first examples) if I add a control array to a form at design time? Or does creating the array on a form at design time create the array?
Thanks for your help!
|
|
|
|
|
No, you need not create a second array. The first example I posted was the simplist one I could think up so that you could see the guts of how to add items to a group of textbox controls.
The second example I wrote accesses the FormName.Controls collection (the design-time "control array" you are asking about) instead of using a ctrlArray variable. If the method you're writing is a member of the form whose textboxes are being updated, then the collection in question would be Me.Controls . This would be the case, say, if you're writing a Windows Application with only one form and one class which defines that form.
In answer to your final question, Or does creating the array on a form at design time create the array? technically the answer is No. It creates a Collection. But for (almost) all intents and purposes, a Collection can be thought of as an array.
Hope this helps.
|
|
|
|
|
Where can i find information on writing a setup project for my app that uses SQL server and crystal reports? I wrote one but when i install on another computer, the crystal report does not load and there is no connection between databases.
|
|
|
|
|
Prototypical Code (class/method structure omitted):
dim FG as ComObject
dim someString as String = "Some String"
FG = new ComObject
Try
FG.someMethod(someString)
Catch ex as Exception
msgbox("Error: " & ex.message & vbCrLf & "(FG is Nothing): " & (fg Is Nothing).toString) & vbcrlf & "(someString is Nothing): " & (someString Is Nothing).toString)
End Try
-------
The output I get is:
Error: Object reference not set to an instance of an object.
(FG Is Nothing): False
(someString Is Nothing): False
I was under the impression that if the "object reference [is] not set to an instance of an object", then that object "Is Nothing" should return True.
Can someone set me straight, please, I'm going nuts trying to figure this one out.
|
|
|
|
|
Hi,
Is it possible that inside FG.SomeMethod, something is trying to reference a null object?
Can you step into the FG.SomeMethod code and see if it is happening INSIDE there?
(side note, the first instance of "(fg Is Nothing).toString)" in your messagebox string should not have the paren at the end) - I just know because I tried to run the code.
Thanks,
-Len Miller
"If I had eight hours to chop down a tree, I'd spend six sharpening my axe."
-Abraham Lincoln
|
|
|
|
|
Good catch on the msgbox string - I missed that.
FG is a 3rd party COM object, so anything is possible inside it. Unfortunately, that also means I can't debug it.
But it sounds like I'm not going nuts - if FG is "not set to an instance of an object" then (FG Is Nothing) would evaluate True.
Thanks for the help.
|
|
|
|
|
Hmm. Too bad you can't debug the method.
What I would do is check the docs of FG & FG.SomeMethod.
Maybe the objects expects that you have already set a property to some object that it is trying to use. Or, maybe it expects that you may have already set some objects that it needs during creation.
Like this:
Dim FG as new ComObject(neededObject)
Or this
FG.NeededObject = neededObject
Maybe THEN you can run
FG.SomeMethod
???
Just a thought...
Good luck
Thanks,
-Len Miller
"If I had eight hours to chop down a tree, I'd spend six sharpening my axe."
-Abraham Lincoln
|
|
|
|
|
My best guess is that there is a variable in FG.someMethod that is causing the problem. Have you tried running your code in debug mode then stepping through line by line with the F11 key till you get to the line causing the error?
|
|
|
|
|
Unfortunately FG is a 3rd party COM object, so I can't debug it.
But it sounds like I'm not going nuts - if FG is "not set to an instance of an object" then (FG Is Nothing) would evaluate True.
Thanks for the help.
|
|
|
|
|
How to calculate the muliplication of 2 fields to next field
on the .NET data grid but run time? If I move up,down,left,right on the grid,it must calculate whenevere change takes place on the grid cell.
e.g There are 3 columns Units,Unit price and Total on the grid. I want to get Total = Units*UnitPrice. I have written some lines for this purpose under the CurrentCellChanged Event but its working in the same row. but I need If I edit the value of Units Column and go to Column other than these 3 by key down or key up.Its working for KeyRight and KeyLeft.
Here is the code that I have Written
dgOrderDetail is the Name of Data Grid.
Private Sub dgOrderDetail_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgOrderDetail.CurrentCellChanged
If dgOrderDetail.CurrentRowIndex >= 0 Then
If Not IsDBNull(dgOrderDetail.Item(dgOrderDetail.CurrentRowIndex, 10)) And Not IsDBNull(dgOrderDetail.Item(dgOrderDetail.CurrentRowIndex, 11)) Then
dgOrderDetail.Item(dgOrderDetail.CurrentRowIndex, 12) = CInt(dgOrderDetail.Item(dgOrderDetail.CurrentRowIndex, 10)) * CInt(dgOrderDetail.Item(dgOrderDetail.CurrentRowIndex, 11))
End If
End If
I am much trapped in this probelm cuz I have to do it on urgent basis.
Plz help me in this regard
|
|
|
|
|
See DataColumn.Expression in MSDN Help.
|
|
|
|
|
Hey, im trying to get a powerpoint presentation to open in VB, so that it runs but the user cant edit it or stuff anything up. Any help would be appreciated. Thanks.
Court
|
|
|
|