473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Call sub from another sub.

137 100+
Hello,
Can i call a sub from another sub?

I short i did this:
Expand|Select|Wrap|Line Numbers
  1.  'Addhandler to the textboxes
  2.                 AddHandler TextField(i).MouseClick, AddressOf Mouse_Click
  3.                 AddHandler TextField(i).KeyPress, AddressOf Text_Save
  4.                 AddHandler TextField(i).LostFocus, AddressOf Text_Focus
  5.                 AddHandler TextField(i).Disposed, AddressOf Text_Dispose
  6.  
  7.                 'Addhandler to the DeleteButton
  8.                 AddHandler DeleteBtn(i).MouseHover, AddressOf Delete_Hover
  9.                 AddHandler DeleteBtn(i).Click, AddressOf Delete_Click
  10.                 AddHandler DeleteBtn(i).Disposed, AddressOf Delete_Dispose
  11.  
  12.                 'Addhandler Picturebox
  13.                 AddHandler ThumbPicturearr(i).MouseClick, AddressOf Thumb_Click
  14.                 AddHandler ThumbPicturearr(i).MouseHover, AddressOf Thumb_Hover
  15.                 AddHandler ThumbPicturearr(i).Disposed, AddressOf Thumb_Dispose
  16.  
  17. 'AND THEN I CREATED THE SUBS
  18.  
  19. 'FOR EXAMPLE
  20.  Sub Text_Dispose(ByVal Sender As Object, ByVal e As EventArgs)
  21.  
  22.         Sender.Dispose()
  23.  
  24.     End Sub
  25.  
  26. 'AND I WANT TO CALL HEM FROM HERE:
  27.  
  28. Sub Delete_Click(ByVal Sender As Object, ByVal e As EventArgs)
  29.  
  30.  
  31.  
  32.         If MessageBox.Show("Delete " & Sender.text & " from the database?" & vbCr & "(Pictures are not deleted!)", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = Windows.Forms.DialogResult.OK Then
  33.  
  34.             DeletSql = "DELETE FROM foto WHERE (id = " & Sender.Name & ")"
  35.  
  36.             If UpdateDatabase(DeletSql) > 0 Then
  37.  
  38.                 Sender.Dispose()
  39.                 Text_Dispose(Sender, e)
  40.                 Delete_Dispose(Sender, e)
  41.                 Thumb_Dispose(Sender, e)
  42.                 MsgBox("Photo (" & Sender.Text & ") removed from the database")
  43.  
  44.             End If
  45.  
  46.         End If
  47.  
  48.     End Sub
In short, when the photo has been deleted, the picturebox, the button and the textbox must be removed/disposed.
Aug 28 '08 #1
3 1671
Curtis Rutland
3,256 Expert 2GB
Sure, why wouldn't you be able to?

This seems like it's one of those things that's faster to try than to ask...

Anyway, while you're here, since you are using VB.NET, you should be using .NET constructs. For example, MessageBox.Show() instead of MsgBox().

Hope that helps.
Aug 28 '08 #2
djpaul
137 100+
Yeah ok, but the msgbox is fine for here.
But the subs doesn't react.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Text_Dispose(Sender, e)
  3. Delete_Dispose(Sender, e)
  4. Thumb_Dispose(Sender, e)
  5.  
Only the button (Sender.Dispose()) disapears.
But the other (above) subs doesn't do anything!
Aug 28 '08 #3
Curtis Rutland
3,256 Expert 2GB
Oh, I see.

Think about it this way. You are passing Sender from your first Sub to your next, and then calling Sender.Dispose(). So you're trying to dispose the same sender every time. You need to pass a reference to the actual object you are trying to dispose. For example: Text_Dispose(TextBox1, e) or whatever your textbox name is.
Aug 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tubby Tudor | last post by:
What is the best way to call one python script from within another python script? For example: one.py finishes succesfully and calls two.py which finishes OK and then calls three.py Thanks...
3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
4
by: Christian | last post by:
From a not even newbie: Without knowing much about Python (yet) I'm trying to install the CMS Zope via FTP (with the well documented changes to make it work on an Apache server). By birth Zope...
1
by: seash | last post by:
hi friends I need to call an event (private void groupBox4_Enter(object sender, System.EventArgs e)) from an another event (private void Appexit_Closing(object sender,...
5
by: Wilfried Mestdagh | last post by:
Hi, I want to overload a constructor of a class. But I want to call the other one from the second if called. I explain with code because of my english: public class XMLConfig { public...
10
by: Daniel | last post by:
Hi all, Have any ideas for the above question? for example, in pageA, i call pageB's buttonA.visible=false. thank you in advance. best regards, GL
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
6
by: mygoogleaccount | last post by:
Hi, may be someone could help me ? i need to use cyrillic letters in a php application. I changed everything to UTF-8 and it works fine. The only problem are CYRILLIC SMALL LETTER ES...
3
by: mandible | last post by:
I'm trying to call one stored procedure inside another. I was wondering if this is possible Some ideas I was toying with is putting the first stored procedure inside of a temp table but haven't...
7
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am trying to see if I can call a Library remotely. The library contains a Form that I want to display then pass back some data to user that called this form remotely. I have it working...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.