|
Hi,
I am stuck on VB.NET 2005, in VB6 i was able to load objects at run-time.
Problem is I am asking user how many textboxes they want and then system will create an array of those textboxes.
Here's the code I was using in VB6. I already had one textbox on form and the index was set to 0.(can't even do that vb.net)
For i = 1 to iSelectedNum
Load TextBox(i)
TextBox(i).Visible = True
TextBox(i).Top = TextBox(i - 1).Top + TextBox(i - 1).Height
TextBox(i).Left = TextBox(i - 1).Left
TextBox(i).Text = ""
Next i
I tried Code Upgrade function from VS 2005 but did not worK!!! Anyone please HELP!!
|
|
|
|
|
Control arrays don't exist under VB.NET.
However, you can create your own quite easily.
Dim myTextBoxes As New List(Of TextBox)
For i = 1 to iSelectedNum
Dim newTextBox As New TextBox()
With newTextBox
.Top = calculated Top value
.Left = calculated Left value
.Text = "whatever text you want"
End With
myTextBoxes.Add(newTextBox)
Me.Controls.Add(newTextBox)
Next
|
|
|
|
|
Thanks a lot Dave. But there's one more question now!? How can i access them (textboxes)?
|
|
|
|
|
Private myTextBoxes As List(Of TextBox)
....
Private Sub CreateTextBoxes(ByVal count As Integer)
myTextBoxes = New Dictionary(Of String, TextBox)
For i As Integer = 1 To count
Dim newTextBox As New TextBox
With newTextBox
.Top = i * 20
.Left = 10
.Size = New Size(100, 18)
End With
myTextBoxes.Add(newTextBox)
Me.Controls.Add(newTextBox)
Next i
...
myTextBoxes(6).ForeColor = Color.Blue
|
|
|
|
|
Thanks for Reply. But there is still one problem in the example of code you wrote, and i cant figure it out why is it happening. It gives me following error
"Error1 -> Value of type 'System.Collections.Generic.Dictionary(Of String, System.Windows.Forms.TextBox)' cannot be converted to 'System.Collections.Generic.List(Of System.Windows.Forms.TextBox)'."
<code>myTextBoxes = New Dictionary(Of String, TextBox)</code>
|
|
|
|
|
Sorry, my mistake. That line should be:
myTextBoxes = New List(Of String)
|
|
|
|
|
In most, if not all, of the Multimedia examples that I'm studying that use MCI functions, alot of the variables are being declared as being of type Integer.
I was wondering why some of them aren't being declared as being variables of type Byte.
As an example: MIDI channels normally will only range from 1 up to 16 and cannot be a negative number.
Still these are being declared as being of type Integer, which takes 2 bytes of memory, if I'm right.
Does anyone know why these aren't being declared as type Byte (which takes only 1 Byte of memory)?
Thanks alot!
Jan
|
|
|
|
|
Jan34 wrote: I was wondering why some of them aren't being declared as being variables of type Byte.
That depends on the function being called and the limitations of VB6. If the function requires a 16-bit signed integer being passed in, a Byte just won't cover it. You MUST match the datatypes of the function being called as closely as possible, but in all cases, you have to pick a type that has a size matching the size of the type expected by the function call. If not, the stack corrupts and the cell will most likely fail, if not your entire application.
Why are you even starting with VB6?? It's a dead language with no further support from Microsoft. You can get VB.NET for free from MSDN.
|
|
|
|
|
I don't know for sure but 2 possible reasons are
1) They wanted to make sure they had a large enough datatype for different options.
2) Although this sounds counter intuitive smaller datatypes are sometimes slower than larger ones. CPUs are generally optimized for certain common datatypes and I think they are optimized for signed (positive or negative) datatypes and usually for datatypes of the processors word size. That would be 32 bits (4 bytes) for most processors out there altough I suppose the newer ones might be optimized for 64 bits.
Unless you have a really large array or something 1 byte of memmory really isn't going to matter much.
|
|
|
|
|
Hello everybody.
I hope this is the right place to post this .
Well, i need to read a stored procedure from vb.net, add some text and compile it.
In other words, i need to modify a stored procedure from vb.net and compile it.
I guess this is possible, but i am not sure how i could do this, maybe using SQLDMO
but i would like to know if someone around here has done this and could give me some advice.
Well i hope i was clear.
Thanks in advance for your time.
Henry de Sousa
|
|
|
|
|
HenrydeSousa wrote: i need to read a stored procedure from vb.net, add some text and compile it.
Are you asking how to read a stored procedure from an SQL Server database, modify that, then put it back in the database and compile it??
|
|
|
|
|
Yes.
For example:
i have this stored procedure:
Before:
CREATE PROCEDURE AddContacts
AS
INSERT INTO Contact
(ContactID, FirstName, LastName) SELECT EmployeeID, FirstName, LastName FROM Northwind.dbo.Employees
GO
i need to read that sp, modify it and put it back in the database and compile it from vb.net.
After:
CREATE PROCEDURE AddContacts
WITH ENCRYPTION
AS
INSERT INTO Contact
(ContactID, FirstName, LastName) SELECT EmployeeID, FirstName, LastName FROM Northwind.dbo.Employees
GO
As you may see i added the text WITH ENCRYPTION. This is what i need to do for every stored
procedure in the database.
modified on Wednesday, January 16, 2008 1:05:30 PM
|
|
|
|
|
OK. After playing around with the SQLDMO COM objects for a little while, it looks like this project will be pretty easy.
I just started with toying with it using this[^] single page and was easily able to connect to the server, enumerate the databases, tables in them, columns, stored procedures, ... I was even able to Script all of these objects very easily.
On the StoredProcedure objects, there's an Alter method that you can use to give the stored procedure a new script.
OOOOORRRRRR
If you're using SQL Server 2005, you can use SMO to do this instead. I think the SMO version is going to be a bit more documented.
|
|
|
|
|
OK. Thanks for your answer.
Let me try it tonight at home.
Henry de Sousa.
|
|
|
|
|
Hi everybody.
Here i want to post the complete code i have finally developed this days to do what i posted a few days ago. I have not found the way to compile the script dinamically, now i have to copy and paste the code in the query analizer, when i find the way to compile the script generated i'll post it here, if someone knows the way to do it, it would be great he/she posts it.
<br />
Imports System<br />
Imports System.IO<br />
Imports SQLDMO<br />
<br />
Public Class SQL_DMO<br />
<br />
Dim oSqlServer As New SQLServer<br />
<br />
Private Sub SQL_DMO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
'txt_bd.Text = "Northwind"<br />
'txt_password.Text = "123"<br />
'txt_servidor.Text = "(local)"<br />
'txt_usuario.Text = "sa"<br />
<br />
Dim i As Integer<br />
Dim oNames As SQLDMO.NameList<br />
Dim oSQLApp As SQLDMO.Application<br />
oSQLApp = New SQLDMO.Application<br />
<br />
oNames = oSQLApp.ListAvailableSQLServers()<br />
For i = 1 To oNames.Count<br />
txt_servidor.Items.Add(oNames.Item(i))<br />
Next i<br />
txt_servidor.Focus()<br />
End Sub<br />
<br />
Private Sub CrearTxt()<br />
Dim fs As FileStream = New FileStream("C:\Script.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)<br />
Dim w As StreamWriter = New StreamWriter(fs)<br />
w.BaseStream.Seek(0, SeekOrigin.End)<br />
w.Write(txt_script.Text)<br />
w.Flush()<br />
w.Close()<br />
End Sub<br />
<br />
Private Sub cmd_conectar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_conectar.Click<br />
'Creamos la conexión<br />
Try<br />
oSqlServer.LoginSecure = False<br />
oSqlServer.Connect(txt_servidor.Text, txt_usuario.Text, txt_password.Text)<br />
'---------------------------------------------------------------------------<br />
Dim oDataBase As Database<br />
'Indicamos la BD a la cual deseamos conectarnos<br />
oDataBase = oSqlServer.Databases.Item(txt_bd.Text)<br />
<br />
'Leemos los procedimientos almacenados de la base de datos<br />
Dim oSP As StoredProcedure2<br />
For Each oSP In oDataBase.StoredProcedures<br />
lst_SPs.Items.Add(oSP.Name)<br />
Next<br />
'---------------------------------<br />
oSqlServer.DisConnect()<br />
cmd_aceptar.Enabled = True<br />
cmd_AT.Enabled = True<br />
cmd_A1.Enabled = True<br />
cmd_QT.Enabled = True<br />
cmd_Q1.Enabled = True<br />
Catch ex As Exception<br />
MsgBox("Ha ocurrido un error en la conexión con el servidor", MsgBoxStyle.Information, "Error")<br />
End Try<br />
End Sub<br />
<br />
Private Sub cmd_aceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_aceptar.Click<br />
If Me.lst_SPsAgr.Items.Count = 0 Then<br />
txt_StatusBar.Text = "NO ha seleccionado nigún procedimiento almacenado"<br />
txt_StatusBar.Refresh()<br />
MsgBox("NO ha seleccionado nigún procedimiento almacenado" & ControlChars.CrLf & "NO se la de de vivo, despiértese!!", MsgBoxStyle.Exclamation, "Atención")<br />
Return<br />
End If<br />
<br />
txt_StatusBar.Text = ""<br />
Try<br />
oSqlServer.LoginSecure = False<br />
oSqlServer.Connect(txt_servidor.Text, txt_usuario.Text, txt_password.Text)<br />
<br />
Dim oDataBase As Database<br />
Dim tot_proc As Integer<br />
tot_proc = 0<br />
'Indicamos la BD a la cual deseamos conectarnos<br />
oDataBase = oSqlServer.Databases.Item(txt_bd.Text)<br />
<br />
'Leemos los procedimientos almacenados de la base de datos<br />
Dim oSP As StoredProcedure2<br />
Dim Script As New System.Text.StringBuilder<br />
Script.Append("")<br />
For Each oSP In oDataBase.StoredProcedures<br />
If lst_SPsAgr.FindStringExact(oSP.Name, 0) <> -1 Then<br />
txt_StatusBar.Text = "Generando script " & Trim(Str(tot_proc + 1)) & " de " & Trim(Str(lst_SPsAgr.Items.Count)) & "... Procedimiento: " & oSP.Name<br />
txt_StatusBar.Refresh()<br />
<br />
Script.Append("/*-- Procedimiento # " & tot_proc + 1 & "--*/" & ControlChars.CrLf)<br />
Script.Append("if exists (select name from dbo.sysobjects where id = object_id(N'[dbo].[" & oSP.Name & "]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" & ControlChars.CrLf & _<br />
" drop procedure [dbo].[" & oSP.Name & "]" & ControlChars.CrLf & _<br />
"GO" & ControlChars.CrLf & ControlChars.CrLf)<br />
Script.Append(oSP.Script())<br />
<br />
tot_proc = tot_proc + 1<br />
End If<br />
Next<br />
txt_StatusBar.Text = "Generando script final para un total de " & Trim(Str(tot_proc)) & " procedimientos, por favor espere..."<br />
txt_StatusBar.Refresh()<br />
<br />
txt_script.Text = Script.ToString<br />
<br />
oSqlServer.DisConnect()<br />
'txt_script.Text = Replace(txt_script.Text, ControlChars.CrLf & "AS", ControlChars.CrLf & "WITH ENCRYPTION" & ControlChars.CrLf & "AS", , , CompareMethod.Text)<br />
'txt_script.Text = Replace(txt_script.Text, "CREATE PROCEDURE", "ALTER PROCEDURE", , , CompareMethod.Text)<br />
cmd_seleccionar.Enabled = True<br />
''''CrearTxt()<br />
txt_StatusBar.Text = "Secuencia de comandos generada exitosamente para un total de " & Trim(Str(lst_SPsAgr.Items.Count)) & " procedimientos"<br />
txt_StatusBar.Refresh()<br />
MsgBox("Se generó exitosamente la secuencia de comandos" & ControlChars.CrLf & "para un total de " & tot_proc & " procedimientos almacenados", MsgBoxStyle.Information, "Información")<br />
Catch ex As Exception<br />
MsgBox("Ha ocurrido un error en la conexión con el servidor", MsgBoxStyle.Information, "Error")<br />
Finally<br />
End Try<br />
<br />
''If lst_SPsAgr.Items.Count > 0 Then<br />
'' Dim i As Integer<br />
'' Dim NombProce As String<br />
'' NombProce = ""<br />
'' i = 0<br />
'' For i = 0 To lst_SPsAgr.Items.Count - 1<br />
'' MsgBox(lst_SPsAgr.Items(i).ToString)<br />
'' Next<br />
''End If<br />
End Sub<br />
<br />
Private Sub cmd_seleccionar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_seleccionar.Click<br />
''txt_script.Select(0, Len(txt_script.Text))<br />
txt_script.SelectAll()<br />
txt_script.Copy()<br />
MsgBox("Se copió la secuencia de comandos en el portapapeles", MsgBoxStyle.Information, "Información")<br />
End Sub<br />
<br />
Private Sub lst_SPs_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lst_SPs.DoubleClick<br />
If lst_SPs.SelectedItems.Count > 0 Then<br />
lst_SPsAgr.Items.Add(lst_SPs.SelectedItem.ToString)<br />
lst_SPs.Items.Remove(lst_SPs.SelectedItem)<br />
End If<br />
End Sub<br />
<br />
Private Sub cmd_AT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_AT.Click<br />
Dim i As Integer<br />
For i = 0 To lst_SPs.Items.Count - 1<br />
lst_SPsAgr.Items.Add(lst_SPs.Items(i).ToString)<br />
Next<br />
lst_SPs.Items.Clear()<br />
End Sub<br />
<br />
Private Sub cmd_A1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_A1.Click<br />
'lst_SPsAgr.Items.Add(lst_SPs.SelectedItem.ToString)<br />
'lst_SPs.Items.Remove(lst_SPs.SelectedItem)<br />
Dim i As Integer<br />
For i = 0 To lst_SPs.SelectedIndices.Count - 1<br />
lst_SPsAgr.Items.Add(lst_SPs.SelectedItems(0))<br />
lst_SPs.Items.RemoveAt(lst_SPs.SelectedIndices(0))<br />
Next<br />
End Sub<br />
<br />
Private Sub cmd_Q1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_Q1.Click<br />
Dim i As Integer<br />
For i = 0 To lst_SPsAgr.SelectedIndices.Count - 1<br />
lst_SPs.Items.Add(lst_SPsAgr.SelectedItems(0))<br />
lst_SPsAgr.Items.RemoveAt(lst_SPsAgr.SelectedIndices(0))<br />
Next<br />
End Sub<br />
<br />
Private Sub lst_SPsAgr_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lst_SPsAgr.DoubleClick<br />
If lst_SPsAgr.SelectedItems.Count > 0 Then<br />
lst_SPs.Items.Add(lst_SPsAgr.SelectedItem.ToString)<br />
lst_SPsAgr.Items.Remove(lst_SPsAgr.SelectedItem)<br />
End If<br />
End Sub<br />
<br />
Private Sub cmd_QT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_QT.Click<br />
Dim i As Integer<br />
For i = 0 To lst_SPsAgr.Items.Count - 1<br />
lst_SPs.Items.Add(lst_SPsAgr.Items(i).ToString)<br />
Next<br />
lst_SPsAgr.Items.Clear()<br />
End Sub<br />
<br />
Protected Overrides Sub Finalize()<br />
oSqlServer.Close()<br />
MyBase.Finalize()<br />
End Sub<br />
<br />
Private Sub cmd_Salir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_Salir.Click<br />
Close()<br />
End Sub<br />
<br />
End Class<br />
Henry de Sousa
|
|
|
|
|
Is it possible to change the size of a buttons in DataGridView ButtonColumn. That is, I want the width of the column to be wider than the width of the button in the column.
Thanks
EM
|
|
|
|
|
There is no property to change the size of the button. You'd probably have to make your own DataGridViewButtonColumn, and possibly, DataGridViewButtonCell classes to give you the ability to supply your own properties and drawing code to change the size of the button, without changing the size of the column.
Google for "custom DataGridViewButtonColumn" for examples.
|
|
|
|
|
Hi Friends,
I new to vb.net. In c#.net in GridView i use RowDataBound method and make a check if commandname is Delete i catch the linkbutton(Delete) by FindControl and on Click i give javascript method for Confirm. If Ok it goes to RowDeleting else Cancel.
I am trying something same in vb.net for DataGrid.
The button in DataGrid is
<asp:ButtonColumn Text="??a??af?" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>
Any idea how can Throw a Confirm Message on Click of This button?
Any help would be greatly appreicated
Thanks
Cheers
Menon
|
|
|
|
|
You should be asking this question in the ASP.NET forum.
To get a confirmation dialog, you'd probably be writing the code in JavaScript on the client-side.
|
|
|
|
|
Hi,
I have a mostly C++ background and have a small VB.NET problem and was hoping for some advice from you guru's out there in VB land. I am using VS.NET 2002, incase anyone know of a problem with that version.
I am trying to access functions in a unmanaged DLL from a managed VB application. I can get this to work fine until I use a DLL function that has a string as a parameter. When I call a function with a string as a parameter, although the DLL receives the string correcly, the return value of all future DLL calls is garbage. I have created a small sample application (DLL and VB) to demonstrate the problem. I have posted the code in this post (sorry about that but figured it would be nessecary).
Any help would be awesome?
Thanks in Advance,
Charles
Example follows, in the VB application the first two calls to fnTestNumber are handled fine, but the return value from fnTestString and the last fnTestNumber are random.
VB Application:
Imports System.Runtime.InteropServices<br />
<br />
Module Module1<br />
<br />
<DllImport("TestDLL.DLL", _<br />
CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)> _<br />
Function fnTestNumber(ByVal iTest As Long) As Long<br />
End Function<br />
<DllImport("TestDLL.DLL", _<br />
CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)> _<br />
Function fnTestString(<MarshalAs(UnmanagedType.LPStr)> ByVal szTest As String) As Long<br />
End Function<br />
<br />
Sub Main()<br />
Dim retcode As Long<br />
<br />
retcode = fnTestNumber(9876)<br />
retcode = fnTestNumber(7654)<br />
retcode = fnTestString("DATAFILE1.DAT")<br />
retcode = fnTestNumber(1234)<br />
End Sub<br />
<br />
End Module
C++ DLL:
__declspec(dllexport) int fnTestNumber(int iTest)<br />
{<br />
return iTest;<br />
}<br />
<br />
__declspec(dllexport) int fnTestString(const char* szTest)<br />
{<br />
return 42;<br />
}
|
|
|
|
|
Hi,
I am used to use P/Invoke between managed C# and native C, here are some suggestions:
- passing a read-only string from managed to unmanaged works fine, it does not even need
MarshalAs(UnmanagedType.LPStr
- by default managed strings are Unicode and get marshaled as 16-bit char collections;
adding CharSet:=CharSet.Ansi should fix that were appropriate.
- I avoid returning a string, since that would mean the unmanaged world needs to create
an object that can continue to exist in the managed world; instead:
- when needing a string result, I tend to pass a StringBuilder object, with its
initial capacity appropriately set, and also pass that capacity; then the unmanaged
world can treat it as a char buffer of specified length.
- always: your calling conventions must match; since I fail to remember the default, I
always make it explicit on both sides.
- most things you do wrong in P/Invoke result in an exception, quite often corresponding
to an access violation.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
In addition to what Luc said, you're using and returning 32-bit numbers in/from your C++ functions, but your VB.NET declarations are Long s. The Long type in VB.NET is a 64-bit signed integer. I think you're actually looking for the Integer type, which is 32-bit signed.
<DllImport("TestDLL.DLL", _
CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)> _
Function fnTestNumber(ByVal iTest As Integer) As Integer
End Function
<DllImport("TestDLL.DLL", _
CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)> _
Function fnTestString(ByVal szTest As String) As Integer
End Function
|
|
|
|
|
Right. I missed that one, although I have made similar mistakes myself.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
modified on Tuesday, January 15, 2008 1:41:17 PM
|
|
|
|
|
Ah...... I knew it would be something really annoyingly simple. Thank you both very much for the help. You have no idea the hours of frustration that saved me.
Thanks again,
Charles
|
|
|
|
|
hi guys,
i'm having one word document(2003) with many pages [eg.. 100 pages],
each page has different headers informations
and footers information, and different body text.
now what i want is,
To read the content of each page and write it to another file [Chk1.doc].
one more thing while writing to a file,
while writing in another file, i don't want header and footer instead i want the every page header information to be written at the top every page and footer information to be written at the end of every page and body of the page in the middle.
i want to do this task in vb.net
Pls help me.
Thnks,
regards,
P.Prakash
|
|
|
|
|