|
Try it out.
This code will read a file and will put file's contents into a string
Dim reader As StreamReader = File.OpenText("c:\myfile.txt")
Dim line As String = reader.ReadToEnd
Manish
|
|
|
|
|
I'm writting VBA macro code with array start index as 1 rather 0
Option Base 1
Dim array() As String
If()Then
ReDim array(5)
'fill array with elements
Else
ReDim array(0) 'This statement gives error
End If
I try to use UBound() and LBound() to determine if the array is empty, but can't make it work.
Someone please tell me if there is other way to make it work.
|
|
|
|
|
You can't ReDim an array down to 0 when the Option Base is 1. The lowest you can ReDim down to, obviously, is 1.
I don't know what you mean by "if the array is empty". It appears as though you're trying to ReDim a variable that was an array to no longer be an array. You can't do that. Once a variable is declared, you cannot change it's type. If it's declared as an Integer or Long, it has to stay an Integer or Long. You can't ReDim it to make it an array of Longs. The opposite is also true. Once delcared as an array, it must stay as an array. You can't ReDim it down to a single-valued variable.
I think the function you're looking for is
IsArray(var). This will return True or False depending on if the var is an array or not.<br />
<br />
<br />
<div class="ForumSig"><font color="Blue">Dave Kreskowiak<br />
Microsoft MVP - Visual Basic</font><br />
</div>
|
|
|
|
|
Hi, Dave,
I declared an array, then under certain conditions, this array will be filled with elements, otherwise it will stay empty.
After get through the condition statements, I need to determine if the array is empty.
I tried to use UBound() and LBound(), but I receive compile error on it when the array is not ReDim and filled with elements. what is the best way to determine if the array is empty?
Thanks
Vicky
|
|
|
|
|
"Empty" can be different things. If the variable is not declared an array, or if the variable is declared an array but has no elements, and it can be declared an array and have empty elements.
It depends on the call that's creating the array. You just have to test it to find out.
IsArray will tell you if the variable is declared as an array, but that's it. If that test passes, then you can check its UBound. If it's greater than 0, the array has elements. After that, you check the value of the first element to see if that value is valid.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
try using this
if ubound(array)>=1 then<br />
'array has elements<br />
else<br />
'array is empty<br />
endif
hope this Works...
Nitin...
|
|
|
|
|
I have selected a file from a listbox that I need to read. The selected file is fileinfo, but all the articles I have read are looking for a string for the file w/path.
silver-gray
|
|
|
|
|
hi,
I want to populate the list from db into my treeview and add textbox to another column corresponding to the each lowest child node of the treeview. i am new to vstudio 2005.but experienced in 2003. i tried all datagridview,treeview and listview controls. but can't find out the solution.
eg.
Parent 1
Child0 of Parent 1
child1 of Child0 Textbox1
child2 of Child0 Textbox2
Child00 of Parent 1
child1 of Child00
child2 of Child01 Textbox3
Parent2
.....
what control can i use to achieve this structure?
this is urgent. any help would be greately appreciated.
also i couldnt find any useful articles which to describe databinding in treeview and listview controls. any useful reference?
Thank you all.
|
|
|
|
|
No control exists that will provide this functionality. You'll have to build one yourself. Search the articles for "TreeListView" and you'll find an example of creating your own TreeView control with similar functionality.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello,
I have created a program that monitors different task being done. I have used the StopWatch class, to start and stop different task and get the duration of time it takes to do them. My problem is I want to be able to display them in a datagrid in another form all different tasks with the running times displayed for each task that is currently being done.
The way my program works is that they will select in the datagrid on the main form the task that they want to start, they could do this for many tasks and have many running at the same time. The customer does not want this information displayed on the main form, but displayed in another form. So even though the task are started on the main form, the display form should somehow be able to view the currently running times. These should be displayed in datagrid as there could be many tasks that will be added and deleted from it.
Is it possible to have global variables across both forms, or is there another way to do this.
Many thanks in advance,
Steve
|
|
|
|
|
You should set up delegates between the two forms to pass this sort of info back and forth. There are no globals in .NET, but you can create a class with public static variables and use those, if you must.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Steve,
There is such a thing that I have used in the past. Below is the code for a VB.NET gui application that has two forms, Form1 and Form2. I hope this helps.
In the code behind for Form1, it starts...
Public Class Form1
Inherits System.Windows.Forms.Form
...
Public Shared GameSelected$ 'name of game selected by user or you could declare it Public Shared String GameSelected
...
GameSelected = "lottery"
...
'in my example, when user clicked on a button, the second form appeared
Private Sub GoToSecondForm_Click(ByVal sender As System.Object, ByVal e As System.EventARgs) Handles GoToSecondForm.Click
Dim secondForm as New Form2
secondForm.ShowDialog()
End Sub
...
End Class
'rest of code below is in Form2
Public Class Form2
Inherits System.Windows.Forms.Form
....
DisplayGamesLabel.Text = "Game Selected =" & Form1.GameSelected
End Class
|
|
|
|
|
hi everyone
i m trying to make a stream ripper for shoutcast server.
i m sending a httpwebrequest to the server but i m when trying to get the respone from the server i get protocol violation error
here is the code for sending the web request:
dim ServerPath as string="/"
Dim Prx As New WebProxy("172.31.101.101", 8080)
Prx.BypassProxyOnLocal = True
Prx.Credentials = New NetworkCredential("xyz", "xyz")
if Not Server Is Nothing Then
Request = CType(WebRequest.Create(Server), HttpWebRequest)
Request.Headers.Clear()
Request.Proxy = Prx
Else
MessageBox.Show("Please enter the name of the server you want to connect to", "Server Address Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End If
Request.Timeout = 500000
Request.Headers.Add("GET", ServerPath & "HTTP/1.1")
Request.Headers.Add("icy-metadata:1")
' Request.UserAgent = "WinampMPEG/5.09"
Try
Response = Request.GetResponse()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error in Connection",MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
|
|
|
|
|
Hello
I have a web application that should send a mail with a text from a textbox to the adress that is in another text box.
Can anyone tell me how 2 do this or send me a link to a tutorial... ? plz
10x
|
|
|
|
|
I suspect that this[^] is the reason someone voted you down.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi all,
I am doing an desktop application in vb.net. For forms i have used the
property formborderstyle=none. So what happens when i minimize the form into
the task bar,and again right click on the form i could not the maximize or
minimize or restore. So please let me know how to do this.
regards
ravindra
|
|
|
|
|
Hi
If you are using the borderstype = none means VB disable the maximised and minimised property so you have to make it enable
Tushar kothari
|
|
|
|
|
Hi Friends,
I need the code to open cash drawer either it will be connected in COM or Serial Port.
Below this code is working VB 6.0.
Open "LPT1" For Output As #1
Print #1, Chr$(27); Chr$(112); Chr$(0)
Close #1
I need the code in VB.NET. Any can change the code to .NET.
Thank's in advance,
Senthil V.
|
|
|
|
|
I believe there is a serial port class in .NET 2.0. But it's new there, so are you using 2.0 or not ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
No we are using .NET 1.0.
|
|
|
|
|
Which port is this drawer connected to? In your original post, you said you wanted the serial port, but yet the code you poasted says its on the Parallel port. There will be a HUGE difference in the two procedures used to send raw data to the drawer based on which port it's connected to.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
how to pass parameter from my windows form to cyrstal report that depend on sql stored procedure
i am using vb.net framework-1.1
|
|
|
|
|
Hi. How can I convert bitmap to JPEG in VB 6.0? Is there any component available?
Thanks in advance
|
|
|
|
|
It's about 5 lines of C++ on a system with GDI+ available, perhaps you could make one ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Can any one tell me the consequences when this devenv.exe gets corrupted due to which type of controls.
Rekha
|
|
|
|