What is the best way to take an array in VB.NET which can either be Nothing or initialised and give it a length of zero?The three options I can think of are:
ReDim oBytes(-1)
oBytes = New Byte(-1) {}
oBytes = New Byte() {}
The first example is what most of the developers in my company (we used to do VB 6) have always used.
I'm working on a program to delete files from a certain folder after they have aged a certain amount of time and either match via regex or extension. I'm running into an issue where files() could be: files(0) = Nothing files(1) = Nothing files(2) = Nothing etc....
Right now the way it is written, I could place Else log(1) = data(1) log(3) = "Array field empty" InsertLog(log)
And the program would log as many files as file(i) = Nothing holds. This would create redundant database records and is not wanted. Is there a way to figure out if ALL files(i) = Nothing and then place code in there to insert into the database?
'If log(3) is successful that means no files were old enough or deleted successfully If log(3) = "Success" And IsArray(files) Then For Each file In files If Not file.IsNullOrEmpty(file) Then 'If files is actually something insert into the log log(1) = file [Code] .....
On a button click I need to test whether or not an array has been filled, if it has the user gets linked to a new form otherwise they receive a message box telling them to first assign values to the array.
I've tried 'If MyArray Is Nothing Then....' and 'If MyArray.Length < 1 Then...' but neither seemed to have worked.
find the first empty value on an array?Say I have a directory and will occasionally be adding and removing items from an array to represent this. How would I go about making a loop until the entry is empty. I've tried various things like if null and that sort of thing but none of them seem to work- the problem is I guess that this array value is empty and the system can't deal with it without throwing an error message.Creating an array of a set size from the start isn't an option as I've no idea how big the directory will ultimately be.
Lets say I declare a public array for a structure, and initially I give it 99 indexes (well 100 with base 0), how would I get the first empty index? I thought of doing it like this but a structure array cannot be nothing:
Dim index As Integer Dim RecipeItem As New RecipeItem RecipeItem.name = InventoryList.SelectedIndex RecipeItem.amount = AddItemAmount.Value For index = 0 To _recipe_item.GetUpperBound(0)
i noticed a problem with a program i made that occurs when an array element is called to use but is empty under a certain condtion therefor throwing an exception. i tried to define that element after the array was initialized to give it a default to use, but its not workin for me?
How do you declare an array when the array is initially empty?? I am taking multiple measurements from a meter that I want to put into an array. How would I declare that?? Here is my code to accept the last measured value.
HTML Dim measResult as string For I as Integer = 1 to 4 measResult = objDevice.gpibRead(i, 30) ''30 is the buffer size Next
How can I set up measResult so it is an array that will hold all of the measurements from the meter?? I have tried Dim measResult() as string, Dim measResult() as String = objDevice.gpibRead(1, 30) but no luck.
I have an array set up to receive the names of forms when they open. The form name is sent as a Form not a String therefore when I run my code I cannot check for whether the field is empty in the normal way (ie. array(1) = "") as the "" are only usable with strings!
Dim Forms(24) As Form Dim i As Integer Dim Free As Integer = -1
[CODE]...
I only need a solution to do the same as array(1)="" but for windows forms.
I have a large one dimensional array that is called ArrayHold which is populated at runtime. I run a loop to scan through the array to find out which elements need to be removed based on a few parameters. This all works great, now I am left with two arrays. The original one and a new one which contains the locations of the elements to be removed.
Original Array: ("A")("B")("C")("D")("E")("F")("G")("H")
Second Array with index/count of elements that needs to be removed: ("0")("3")("5")("7")
End result should be preferably not in a new array but a "ReDim" of the original array:("B")("C")("E")("G")
What would be the simplest way to achieve this? I could run a loop to make all the elements that need to be removed "0" or ""? Would there be an easy way of resizing and array by dropping/removing all the white space or empty elements?
I have created a page and made some changes by applying templates and gridview in Updatepanel.Now i have a footer template to add and insert the data to database.But it doesnt appear when the there is no data in datatable.I need to show those footertemplate during page load event.and when i add it has to refresh the page to show the Datas.Page load event:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load, UpdatePanel1.Load If Not IsPostBack Then BindData()
i have made a button that opens a msgbox dialog what i need is to make it show a msgbox with an empty textbox inside and an ok cancel button,so when a user clicks it,it appears and asks for an url string and then,if uses pressed ok,the url should be placed as a movie to axshochwaveflashobject like this Private Sub FromUrlToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FromUrlToolStripMenuItem.Click If FromUrlToolStripMenuItem.Pressed Then MsgBox("emptytextbox",title "Enter the url") If MsgBoxResult = ok Then AxShockwaveFlash1.Movie = "msgbox answer"AxShockwaveFlash1.Refresh() End Sub
i have a string array that i want to output to a text file. the array size is 10000. i fill the array starting from 0 with some strings. at the end, i only want to show the array from index 256 to the last array that is not empty (for eg. if the array is filled with data from 0 to 2000, i only want the text file to show the data from 256 to 2000 and ignore the remaining strings). Is there any function to do this?t i use is shown below
Dim myArray(10000) as string Dim strArray As New System.IO.StreamWriter("c:List.txt") strArray.WriteLine("{0,10}{1,30}", "Index", "Symbol")
i have a string array that i want to output to a text file. the array size is 10000. i fill the array starting from 0 with some strings. at the end, i only want to show the array from index 256 to the last array that is not empty (for eg. if the array is filled with data from 0 to 2000, i only want the text file to show the data from 256 to 2000 and ignore the remaining strings). Is there any function to do this? i am using visual basic express 2008. The code that i use is shown below
Public Class Form1 Dim str As String Dim strA() As String Dim strB() As String Dim f As Integer = -1 Private Sub btngo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngo.Click If txtmain.TextLength > 0 Then str = txtmain.Text
I have a DataGridView that has some columns with dates. It binds to an in-memory Datatable which gets loaded from an string array of data passed back from the backend Some of the rows returned have nulls for the date columns. Solution 1: If I define the Date column in the DataTable as "string" I can easily convert those nulls to empty strings and display it in the grid as empty strings (desired results). However, if the user clicks on the date column header to sort by date, it doesn't order the rows as you want. You get a purely string sort order. Not acceptable
This must've have been asked before but I couldn't locate it. In a mixed code project (VB and C#) we were debugging some old Visual Basic code where a statement as follows could be found:
If Request.Params("xxx") <> "" Then 'do something
I considered this a bug as Request.Params could be null, in which case the statement would've become false which wasn't the idea. So I thought. I just found out, -- probably for the tenth time and I will keep forgetting -- that the following two statements are not equal, while Nothing in VB should be equal to null in C# (thought I):
if(String.Empty == null) // always false If String.Empty = Nothing Then ' always true
Should I dismiss this as a typical Microsoft backward compatibility effort, or should I consider this a huge error in the VB.NET compiler? Does anybody know the Microsoftean opinion on this oddity?
is there a way to make an arry of buttons in vb.net in VB6.0 there is a prop of buttons name Index but not in VB.NET so if there is some way to do that,[code...]
i want to make a vb.net program that reads from a text file a movie, with the help of a Open Dialog (called openFD in my program) (we don't know how many movie we've got), the actors, the release date, the country, and the rating.
First question: How can I make a 2-dimensional array? line(0,0) - Movie1, ... , line (1,5) - Rating2. Here Is my try, but it's not good:
Dim line As ArrayList = New ArrayList() Dim itm As ArrayList = New ArrayList() Dim i As Integer = 0
[code]....
And here is the code for the Delete Button. It deletes a movie from the listbox, but the details of the deleted movie remains for the next one, I must delete the details for the deleted movie, too.
I've been making a table control for a few days, and I've got to the point of making it capable of accepting new data. To do this, I'm making it generate a row of text boxes, combo boxes, and date selection windows along the row that you're entering data into.
I've tried using an array of 'control' types and changing them to whatever specific control I need as I generate it. That sort of works. For example, the code under 'Case "Employees"' below will make a combo box display on the form, but 'ControlArray(i).Items.Add' gives an error because it doesn't think that ControlArray(i) is actually a combobox yet.
You might also be interested to know that everything will have to be dynamically generated since the table I'm using will not always be the same (and the Select Case code will eventually be replaced by something that checks for relationships in the database).
Dim ControlArray(NumberOfColumns - 1) As Control For i As Integer = 0 To NumberOfColumns - 1 ControlArray(i) = New TextBox
I am trying to make an array of picturesbox's. Now I need one array to loop though all the pictureboxs on the form and add them to the array. I also need another array to loop though all the picturebox's on the form however I only want it to add the ones that there names start with "ladder_" How can I do this?