|
because your TextBoxes have names you are not looking for?
because they aren't part of your Form, but are part of another container (Panel, GroupBox, ...)?
because they aren't exactly TextBoxes? (maybe MaskedTextBox)
because your input parameters are wrong? (such as j=0)
because you are calling the SUB when the Form isn't holding anything yet/any more?
your guess could be even better as mine...
|
|
|
|
|
Hi
It might be handy to emit the name and types of the controls that you encounter to the debugger. Something similar to the code below would reveal the names of the components on your form that get looped;
Public Function TotalSub(ByVal j As Integer, ByVal diameter As String, ByVal thickness As String, ByVal material As String)
Dim txtGG, txtYL As TextBox
Dim b As String = ""
Dim sum As Single = 0
For Each ctrl As Control In frmQia.Controls
System.Diagnostics.Debugger.WriteLine ("Type {0}, named {1}", ctrl.GetType().FullName, ctrl.Name)
If Not TypeOf ctrl Is TextBox Then Continue For
For i = 1 To j
If ctrl.Name = "txtTJGG" & i Then
txtGG = ctrl
I'm guessing that the TextBox is contained inside another control. That means that you'd have to loop the Controls -collection of the Control that you've put the textbox in.
I are Troll
|
|
|
|
|
Did you put these TextBoxs in another container on the Form such as a Panel?? If they are inside another container, you won't find them because they are not in the Forms Controls collection.
|
|
|
|
|
Hi,everyone!The Textboxes were in a Tabpage which was in the Form I wrote in code to find. So I should find textboxes I need in frmQia.Tabcontrol1?
|
|
|
|
|
Yes you would go through the controls on the tab page
e.g. where 0 is the tab page you want to check for controls
For Each ctrl As Control In TabControl1.TabPages(0).Controls
.... do checks and other stuff here
Next
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
Thank you, I will try it now!
|
|
|
|
|
Hi,Simon! I have tried what like you said,but it didn't find the textboxes.In this project, the Form "frmQia" was Inited after I clicked a button and after I inputed some textes in it, I would leave it. The sub that I wrote will be called in another Button_Click event after I leave the form.I think the form "frmQia" has hold the textboxes and their name were right.So...What happened to me...
|
|
|
|
|
It sounds as if you are trying to get values from one form by clicking a button on a different form.
If so, Passing Values between Forms in .NET 1.x with C# and VB.NET examples[^] might be useful to you.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hello,Henry! Thanks for your suggestion and the artcile.I've read it.It also give me some help!I have solved this quesiton with all you suggest.Finally I found the textboexes were in a form's tabpage's pannel.
Thanks all of you!
|
|
|
|
|
i have this code:
type
Symbol = string[8];
SymTab = array[1..1000] of Symbol;
TabPtr = ^SymTab;
var
ST: array[1..MaxEntry] of Symbol;
SType: array[1..MaxEntry] of char;
132 function Lookup(T: TabPtr; s: string; n: integer): integer;
133 var
134 i: integer;
135 found: Boolean;
136 begin
137 found := false;
138 i := n;
139 while (i > n) and not found do
140 if s = T^[i] then
141 found := true
142 else
143 dec(i);
144 Lookup := i;
145 end;
152 function InTable(n: Symbol): Boolean;
153 begin
154 InTable := Lookup(@ST, n, MaxEntry) <> 0;
155 end;
when i complier with gpc , it will print this:Tiny10.pas: In function `InTable':
<b>Tiny10.pas:154: error: passing arg 1 of `Lookup' from incompatible pointer type
Tiny10.pas:132: error: routine declaration</b>
can you tell me why? actually,i just know C++, i learn pascal for i read a book which use it.
thank you
<div class="signature"><div class="modified">modified on Tuesday, December 7, 2010 3:53 AM</div></div>
|
|
|
|
|
Hi,
1.
this is not the right forum for this. Your code might be Pascal, it certainly isn't Visual Basic.
2.
I don't know the answer, I would however try again without the '@' in line 154
3.
yes, I use line numbers to my advantage, and so should you; tell your IDE to show line numbers, look at such details when the compiler or run-time reports problems, and when you post, indicate which line has what line number of interest.
|
|
|
|
|
This is Pascal, not VB. Maybe the Delphi forum would have been better for this question. Anyway:
ST is declared as array[1..MaxEntry] of Symbol
TabPtr is declared as ^SymTab (pointer to SymTab)
T parameter in Lookup function is declared as TabPtr -- ^SymTab
So, declare ST as SymTab and it should work.
|
|
|
|
|
|
Hi All,
I'm writing a simple sql editor for our solid databases, and after the information has been retrieved I need to be able to display the field lenght for the column on the Database.
I fill the datagridview like this:
Private Sub applysql(ByVal query As String, Optional ByVal transaction As Odbc.OdbcTransaction = Nothing)<br />
Try<br />
Dim command As New Odbc.OdbcCommand(query, solid, transaction)<br />
datareader = command.ExecuteReader<br />
<br />
bindingsource.DataSource = datareader<br />
resultsdatgdvw.DataSource = bindingsource<br />
resultsdatgdvw.Update()<br />
resultsdatgdvw.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader)<br />
resultslbl.Text = "Returned " & resultsdatgdvw.RowCount & " rows"<br />
If Rollbackbtn.Enabled = False Then<br />
transaction.Commit()<br />
End If<br />
<br />
datareader.close()<br />
datareader.dispose()<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try<br />
End Sub
and then wnat to display the tooltip with the information on like this:
Private Sub resultsdatgdvw_CellToolTipTextNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellToolTipTextNeededEventArgs) Handles resultsdatgdvw.CellToolTipTextNeeded<br />
If e.ColumnIndex > -1 Then<br />
e.ToolTipText = "Type: " & resultsdatgdvw.Columns(e.ColumnIndex).ValueType.ToString & " Length: " & 'Here is where I need to find the max length of the field <br />
End If<br />
End Sub
Any help appreciated!
Chris
|
|
|
|
|
Chris,
to get the metadata for the database objects, i think you need to look at using sys.Objects/sys.Columns in your query. Probably simpler if you add a sp to the db and call that.
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Hi thanks for the advice (although I don't have a clue what a 'sp' is!)
I found the info I needed in the following way:
once I retirved the data and updated the datagrid view I created a seperate datatable and filled it with the schema table of the datareader
bindingsource.DataSource = datareader
resultsdatgdvw.DataSource = bindingsource
resultsdatgdvw.Update()
resultsdatgdvw.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader)
Dim datatable As New DataTable
datatable = datareader.GetSchemaTable()
This puts the metadata for the columns into a table. I then looped round the rows in this table (each row being a column in the datareader) using each rows 'ItemArray' property to first map the row to the column header in the datagrid - ItemArray(0) - and then getting the type - via the datagrids column valuetype - and then maxlength - ItemArray(2) - and then nullable boolean - ItemArray(8).
I added all of this to the header cell of the column corresponding to the row in the datagrid view (I removed the tooltip from the other cells)
For Each row As DataRow In datatable.Rows
Try
resultsdatgdvw.Columns(row.ItemArray(0).ToString).HeaderCell.ToolTipText = "Type: " & resultsdatgdvw.Columns(row.ItemArray(0).ToString).ValueType.ToString.Replace("System.", "") & " Length: " & row.ItemArray(2).ToString & " Nullable: " & row.ItemArray(8).ToString
Catch ex As Exception
End Try
Next
datatable.Dispose()
For some reason the 'key' value in the ItemArray didn't return the correct value but I'm guessing that's just the database I'm using..
Chris
|
|
|
|
|
The file saved by this sub contains only a black rectange of the correct size. I have also tried bmp and jpg with same results.
I am using Vista 64 bit operating system and Visual Studio 2010, Traget CPU: x64, Traget FRamework: .NET Framework 4.
Private Sub MAIN_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim tHeights, tWidth As Integer
'Define the text and layout
Dim txt As String = "Verdicrete Countertops"
Dim the_Font As New Drawing.Font("Helvetica", 28.5, FontStyle.Regular, GraphicsUnit.Pixel)
Dim string_size As SizeF = e.Graphics.MeasureString(txt, the_Font)
tHeights = CInt(string_size.Height)
tWidth = CInt(string_size.Width)
Dim Bitmap As New System.Drawing.Bitmap(tWidth, tHeights)
Using gr As Graphics = Graphics.FromImage(Bitmap)
Dim objBrushBackColor As New SolidBrush(Color.White)
'writes to bitmap and hence the file saved
gr.DrawString(txt, the_Font, Brushes.Black, 0, 0)
' writes to screen only
e.Graphics.DrawString(txt, the_Font, Brushes.Black, 0, 0)
Bitmap.Save("c:\windows\temp\Verdicrete.gif", System.Drawing.Imaging.ImageFormat.gif)
End Using
Bitmap.Dispose()
End Sub
modified on Sunday, December 5, 2010 7:03 PM
|
|
|
|
|
...and what does this mean? A hex dump of an image files tells us nothing.
What do you mean "does not save image"?? What DOES happen? What is expected to happen? Are there any expections? What are those messages? What exactly are you trying to save? Do you have an alpha channel? What format are you trying to save in? and, the MOST important thing, WHAT IS THE CODE YOUR USING TO SAVE THE FILE?
|
|
|
|
|
I HAVE UPDATED MY POST TO INCLUDED MY CODE.
|
|
|
|
|
Ok, but NO NEED TO SHOUT about it!
|
|
|
|
|
Sorry...didn't notice cap lock on.
|
|
|
|
|
Hi,
I see you are new here, so welcome to CodeProject.
When you encounter a problem, you can ask here, and expect a number of people to try and help you; however you have to help them help you by asking a clear question, giving some context, explaining what it is you are trying and what exactly is going on and not to your liking. In this case you should explain how you are saving the image ("using program so-and-so", or "with the following code"), how you are trying to open that image again ("using program so-and-so", or "with the following code"), and then describe what exactly makes you decide it does not work. Is there an exception thrown? show it to us. etc.
With the little you provided we can not determine whether the problem, if any, is in saving the image, or in reading the image. You can't expect someone to type your hex stuff into an app to check whether it is a legal image file...
BTW: if you show a code snippet, make sure to use PRE tags, such as provided by the "code block" widget (and not CODE tags!)
|
|
|
|
|
I HAVE POST MY CODE TO THIS POST.
|
|
|
|
|
OK,
1. the initial state of a new Bitmap is all black, which corresponds to pixels with R=G=B=0, so no surprise you won't see the text from DrawString at all. Start fill a FillRectangle of the required color, probably Brushes.White
2. Not sure why the ellipse would not show. Maybe you looked over it.
3. Transparency is tricky, I hardly ever use it. Some image formats can't handle it and will ignore it, others will deal with it OK. I suggest you perform your initial experiments without transparency.
4. You have some more objects that need disposing: a Font, a Graphics.
|
|
|
|
|
Thank you for your assistance. I made the change you suggested and got a white rectangle but no text. Any suggestions?
Private Sub MAIN_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim tHeights, tWidth As Integer
'Define the text and layout
Dim txt As String = "Verdicrete Countertops"
Dim the_Font As New Drawing.Font("Helvetica", 28.5, FontStyle.Regular, GraphicsUnit.Pixel)
Dim string_size As SizeF = e.Graphics.MeasureString(txt, the_Font)
tHeights = CInt(string_size.Height)
tWidth = CInt(string_size.Width)
Dim rect As New System.Drawing.Rectangle
rect.Width = tWidth
rect.Height = tHeights
Dim Bitmap As New System.Drawing.Bitmap(tWidth, tHeights)
Using gr As Graphics = Graphics.FromImage(Bitmap)
Dim objBrushBackColor As New SolidBrush(Color.White)
gr.FillRectangle(Brushes.White, rect)
e.Graphics.DrawString(txt, the_Font, Brushes.Black, 0, 0)
Bitmap.Save("c:\windows\temp\Verdicrete.gif", System.Drawing.Imaging.ImageFormat.Gif)
End Using
Bitmap.Dispose()
End Sub
|
|
|
|
|