Syntax: "Exit Sub" Or "Return" In Sub Routines
Jun 17, 2009Both seem to accomplish the same thing--exit a subroutine. Is there any difference in how they work under the covers?
[Code]...
Both seem to accomplish the same thing--exit a subroutine. Is there any difference in how they work under the covers?
[Code]...
Is there any difference between Exit and Return?
View 5 RepliesIn VB.NET on a boolean function if you run an Exit Function line will it return false?
View 4 Repliesin my following code, i get the warning doesn't return a value on all codepaths
Public Function getbacktrace(ByVal backtrace As Integer) As StackFrame
With New System.Diagnostics.StackTrace()
If .GetFrame(backtrace + 1) Is Nothing Then
exit function
[code]....
if i change exit function to return new stackframe,anyway, why doesn't Exit Function automatically returns a "dead" stackframe?
I have the following piece of code: trying to use this in 2.0 framework. getting error for not having a return statement before exit function.[code]...
View 4 RepliesFollowing code properly populates "wksSheetNames" Dictionary
Dim wksSheetNames As New Dictionary(Of String, String)
For Each Wks In xlsWB.Worksheets
Wks.Activate()
wksSheetNames.Add(xlsApp.ActiveSheet.codename, xlsApp.ActiveSheet.name)
Next
For example assume the code logic is correct (I know that the syntax is not correct)If wksSheetNames.(Key="Sheet2", Value="Inventory") then Stop What is the correct VB.Net syntax to "Stop" in the above line?
Function f(ByVal x As String, ByVal y As Integer, ByVal z As Integer, ByVal w As Integer, ByRef t As String) As String
If Length(x) < w Then // Definition for Length below
Return t
End If
[CODE]...
I am not a VB programmer, but I assumed for the most part that the syntax is C like, I received the program above from a non-technical recruiter with the following input f1("enritcde3 dtyeds4t8", 2). From my understanding the following output would be ("enritcde3 dtyeds4t8",2,2,2,""). Am I missing something?
I keep getting an error saying "there is an error in your sql syntax." when i use this sql statement:SELECT * FROM gsm_oceanwide_integrationEDIT:To put this in context heres the code im using this query statement in (VB.net):
Dim con As MySqlConnection = New MySqlConnection("Data Source=" & frmLogin.txtserver.Text & ";Database=stratocast;User ID=" & frmLogin.txtusername.Text & ";Password=" & frmLogin.txtpassword.Text & ";")
[code]......
The following code works just fine:
Dim wksSheetNames(0 To xlsWB.Worksheets.Count - 1, 0 To 1) As String
Dim i As Integer = 0
For Each Wks In xlsWB.Worksheets
Wks.Activate()
wksSheetNames(i, 0) = xlsApp.ActiveSheet.codename
[Code] .....
What is the best vb.net based search method that would permit me to search for i.e. "Sheet2" and be able to obtain "Cats"? I attempted to ascertain the index number of "Sheet1" with:
Dim SheetArrIndex As Integer = Array.IndexOf(wksSheetNames, "Sheet1")
Then obtain the value "Cats"
wksSheetNames(SheetArrIndex, 1)
But I received an error message:
Code Line ->>>> "Dim SheetArrIndex As Integer = Array.IndexOf(wksSheetNames, "Sheet1")"
Error msg ->>>> "Only single dimension arrays are supported here.:
Obviously I do not know how to Search and Return the results of a 2D array.
I'm developing a program using VB 2005.I've tried to use the following instructions to "kill" the application
Application.Exit()
Environment.Exit(0)
(not at the same time)
[code]....
I'm having a bit of a problem getting my application to close properly. Basically I have one main form from which all other forms open. If a user tries to close that main form, I want to bring up a MessageBox asking if they want to exit the application.However, when I try to do that it asks the question twice. It seems that the Application.Exit() is triggering the FormClosing event again for some reason, but I don't know of another way to exit the application. BTW, the main form isn't the startup form so I can't use the option to close when the startup form closes.
View 9 RepliesNow I have a sub to validate a bunch of textboxes and combo boxes.I previously used many IF statements to validate and pop up different messageboxes and Exit Sub in every IF statement.But I heard that too many Exits will decrease the efficiency and they were not recommended to use. Instead, nested IF is better because it will let the process naturally go to the end.Then I found out that if I use nested IF,it will be hard to read, since messageboxes are all separated from conditions.
View 2 RepliesHow do I exit from the recursive loop from the code below. I would like to notify the end-user to select a checkbox in a msgBox before I exit the loop.
[Code]....
I have a slew of sub routines that I need to use in my software because each website that I will be accessing don't all use the same methods.....go here...click that...go here...click that...etc etc
So I've divided them into sub routines and call them when I need them but the coding is getting so long that it's becoming confusing to keep up with each sub.
Is it possible to place the sub routines into an independent file like a class and then call them from the file when I need them so I can free up some space to code?
I am listing the following three subrointines....
Private Sub OutPut(ByVal Offset As Long, ByRef path As String) 'Orig
If Not cbFiles.Checked Then
item1 = New ListViewItem(Offset)
[Code]....
They have the same name but a) different types of aguments or different numbers of arguments. This is legal in VB.
VB 2010 express Win XP pro I'm tryimg to detrmine the time taken for various routines, and not having much luck.From what I can gather, it seems that short times and very long times are a problem, as is my understanding of what I have read. cpu speed shown is correct.I checked a few routines, very short routines return 0, to be expected, ?resolution.Longish times (about 33 seconds with a stopwatch), report to be 177 seconds.
[Code]...
I'm trying to have it so that when the user selects an item from the combo box, it will display the right nodes for that selection in the treeview control. For example: User selects Artist from the combo box and the treeview displays the letter of the artist. The user selects a letter and it will display all artist with last names beginning with that letter. Unfortunately when I select a selectedindex, the treeview doesn't display anyting, it's blank. What am I doing wrong? Here's the code I'm using for artists:
[Code]...
I have some common code that I would like to share between pages and I have been messing around with App_Code classes which is great but I would also like to use code that affects drop down lists example:
Sub Set_FirmType(ByVal Sender As Object, ByVal E As EventArgs)
subcategories.Visible = "false"
supplycategories.Visible = "false"
[code]....
Is their a way to put this in my App_Code class?
Note that I'm aware of other yield in vb.net questions here on SO. I'm playing around with Caliburn lately. Bunch of great stuff there, including co-routines implementation.
Most of the work I'm doing is C# based, but now I'm also creating an architecture guideline for a VB.NET only shop, based on Rob's small MVVM framework.Everything looks very well except using co-routines from VB. Since VB 10 is used, we can try something like Bill McCarthy's suggestion:
[Code]...
It definitely isn't as elegant as C# version, but it looks to be doable. We'll see if there are any problems with this. If anyone has better idea, I'm all ears.
I have LaPack numerical package , I want to compile with Visual Fortran (INTEL) using vs2008.I want to use the routines from a VB.NET program.How can I call the routines from VB ?
View 9 RepliesThis will no doubt sound like a pretty dumb question to some, but, despite having written many useful single-thread apps over the years, I don't understand enough about threading yet.
Consider this scenario:
There are four modules, each on its own thread, that can happily run concurrently most of the time. However, each module occasionally causes a few seconds' intensive disk activity (by design) and it would be more efficient (faster, less fragmentation) if only one module at a time wrote to the same physical drive.
It would be useful to have something like a baton that modules within a given scope can pass around, perhaps dependent on their respective priority levels.
I'm using PInvoke to access some routines from a third party library, however i'm getting SEHExceptions when trying to use callbacks defined for one particular method. The callbacks are used to provide feedback from other unmanaged methods within the third party library, passing a string back to the calling application containing a status message.
[Code]...
I am trying to retrieve all processes running on a machine with the usual information; process id, name and the memory usage. I am trying to export it all under one xml file, however to get all the information I had to use 2 separate methods. To get the process id, name and session id (process owner) I used the following code along with a dictionary and a class, using a .net library called Cassia.
Using server As ITerminalServer = manager.GetRemoteServer("Spartacus")
server.Open()
For Each process As ITerminalServicesProcess In server.GetProcesses()
If Not String.IsNullOrEmpty(process.ProcessId) Then
dictprocess.Add(process.ProcessId, New Processes(process.ProcessId, process.ProcessName, process.SessionId))
[Code] .....
As you can see the unique id (process id) is the same in each xml. Is there any way I can write the xml so that the information from both methods can be under one tag?
i have a need for my vb.net app to perform methods at regular intervals. it needs to check sql tables and react to data found, send email and sms messages. i've tried using a loop but this only allows me to perform 1 check ie checking sql tables. the app needs to execute a method every x minutes. i tried using system threading but i got errors.
View 1 RepliesI have a Windows Forms app, with a TabControl. On the first tab (which is a bunch of textboxes), the CTRL-x/c/v keyboard shortcuts for cut/copy/paste work as expected. On the second tab (which is a DataGridView), the keyboard shortcuts don't do anything. How do I hook up these keypress events to my cut/copy/paste routines? I already have great cut/copy/paste routines for my DataGridView--and they work fine when launched from the tooltip buttons or menus. I just need to hook up those subs to the CTRL-x/c/v keypress events.
View 2 RepliesIs there a way to annotate functions, subs, properties, and methods so that tool tips will pop-up in the IDE as they're being defined or selected?
View 2 RepliesI'm writing a really simple file updater which downloads files off from a website and saves them. The download routine is working well, except that it freezes the project while attempting to connect to the host. Easily solved with threading except now when I try to access other form items such as text boxes, labels, form caption, it says I am not doing it in a safe manner and prompts an interrupt in debug. I did some reading on it and I'm still not sure what to do, I'm very new to vbnet and it is still a little confusing to me.
Error: Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.
Imports System.Threading
Imports System.Net
Imports System.IO
[code]....
I have just done my program, just skeleton not completely, the final problem has not been solved up to this time.When I run my application, the Icon of its will be showed at TaskTray. I would like the icon is there when I exit fom of application and then If I double click on the Icon, the application will be showed.
View 5 RepliesThe VB format(object,formatString) command fails when placed in the handler routines of a DataGridView.In the following procedure the newCellValue returns the Format string value instead of a formatted cell value.This pproblem occurs in both the dgv_CellFormatting and the dgv_CellClick routines.The same commands work properly when placed in a procedure on the form.
Private Sub dgv_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgv.CellFormatting
If e.FormattingApplied = False And Not e.CellStyle.Format = Nothing Then[code]...........
I am having an issue trying to figure this out. I am writing a script editor that uses tabs (a tab control) and I want to implement syntax highlighting. My issue is that every sample I can find on syntax highlighting uses
Private Sub RichTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged