|
I suspect the problem is that the array needs to be passed ByRef , which isn't supported in property setters. Try replacing the property setter with a method:
Public Property StringArray() As <MarshalAs(UnmanagedType.SafeArray, safearraysubtype:=VarEnum.VT_BSTR)> String()
Get
Return mStringArray
End Get
End Property
Public Sub SetStringArray(<MarshalAs(UnmanagedType.SafeArray, safearraysubtype:=VarEnum.VT_BSTR)> ByRef value As String())
mStringArray = value
End Sub
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I read setting the parameter ByRef and not ByVal would work but wasn't sure how to set it up.
A little tweaking and the vb.net code looks like this:
<ComClass(clsValues.ClassId, clsValues.InterfaceId, clsValues.EventsId)> _
Public Class clsValues
#Region "COM GUIDs"
Public Const ClassId As String = "095dc64d-141f-46f9-9af2-1c5e633b459b"
Public Const InterfaceId As String = "86ec1f14-1ef4-446d-9172-b92cf260cd16"
Public Const EventsId As String = "1605e412-8b11-4ee0-a34c-9ec04464737f"
#End Region
Public Sub New()
MyBase.New()
End Sub
Private mSingleString As String
Public Property SingleString() As String
Get
Return mSingleString
End Get
Set(ByVal value As String)
mSingleString = value
End Set
End Property
Private mStringArray As String()
Public Function StringArray() As <MarshalAs(UnmanagedType.SafeArray, safearraysubtype:=VarEnum.VT_BSTR)> String()
Return mStringArray.ToArray
End Function
Public Function StringArray(i As Short) As String
Return mStringArray(i)
End Function
Public Sub SetStringArray(<MarshalAs(UnmanagedType.SafeArray, safearraysubtype:=VarEnum.VT_BSTR)> ByRef value As String())
mStringArray = value
End Sub
End Class
The final vb6 code looks like this:
Option Explicit
Private Sub btnTest_Click()
Dim x As Integer
Dim strTest(4) As String
strTest(1) = "abc"
strTest(2) = "def"
strTest(3) = "ghi"
strTest(4) = "jkl"
On Error GoTo err1
Dim clsTest As comtest.clsValues
Set clsTest = New comtest.clsValues
clsTest.SingleString = "this is my string"
clsTest.SetStringArray strTest
MsgBox "Single string = " & clsTest.SingleString, vbInformation, "Test"
For x = 1 To UBound(clsTest.StringArray)
MsgBox "Multi string " & x & " = " & clsTest.StringArray_2(x), vbInformation, "Test"
Next x
Exit Sub
err1:
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description, vbCritical, "btnTest_Click"
On Error Resume Next
End Sub
Thank you for the help - Mark this one as solved
|
|
|
|
|
how to display an mp3 file in a folder using listview, ...
|
|
|
|
|
ApRian AnThye wrote:
how to display an mp3 file in a folder using listview, ... ..open the VS IDE, start a new (WinForm) project. Throw a ListView on your Form1 and add below code;
Public Sub New()
InitializeComponent()
For Each item In IO.Directory.EnumerateFiles("D:\Documents\Music", "*.mp3")
ListView1.Items.Add(item)
Next
End Sub
You'd need to "uncomment" the last two commented lines if you want it to presented as a details-view.
If this is not what you meant, then you'll have to explain what you mean with "display".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
how can i make my client automatically logout when their session time is out?
|
|
|
|
|
Because the web is a disconnected medium you have to keep track of it on the client side using a timer. It is not a simple thing to do. I would search google for some samples because there is too much code to explain it fully here.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hi everyone,
I need help with the following issues:
I have a SQL table namely
tddocument:
Fileid_PK int
Filename varchar(100)
Extension varchar(50)
Content_document varbinary(MAX)
PDF_doc image Checked
File_location varchar(100)
Case_reportID_FK int
A dataset : tdDocument_dataset
A Vb_form name (Save_PDF_Document)
I put all items from the table on the form as controls.
I put a browse button on the form. here is the code under the button:
Dim openfd As New System.Windows.Forms.OpenFileDialog
Dim ms As New IO.MemoryStream
openfd.InitialDirectory = "C:\"
openfd.Title = "Open a PDF file"
openfd.Filter = "PDF files|*.pdf"
openfd.ShowDialog()
File_locationTextBox.Text = openfd.FileName
Me.PDF_docPictureBox.ImageLocation = openfd.FileName
Save_button to save. Here is the code:
Try
Me.Case_reportID_FKLabel1.Text = Me.Case_reportID_PKLabel1.Text
' SavePDFtoSQL()
Me.Validate()
Me.Table_DocumentBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Document_DataSet)
Catch ex As Exception
MsgBox(My.Settings.ERROR_msg, vbCritical, "Erreur")
End Try
When I look at the table record from SQL I see the PDF_doc with a <Binary Data> record. meaning something saved.
Now I Have a data grid view(View_DocumentDataGridView)
I double click on it to open another form namely (Frm_PDF_Viewer)so I read the PDF file associates with the grid as follow:
If frm Is Nothing Then
frm = New FrmPDF_Viewer()
frm.Text = "RAPPORT D'ENQUÊTE"
frm.ID = Int(Me.View_DocumentDataGridView.Item(0, IndexRows).Value)
frm.modification = 1
frm.access_level = Me.access_level
frm.User_ID = Me.User_ID
frm.Usergroup = Me.Usergroup
frm.ShowDialog()
End If
when the form FrmPDF_Viewer open under the load I have this:
Try
Me.Fileid_PKLabel1.Text = ID
Me.View_DocumentTableAdapter.FillByfileid_PK(Me.View_Document_DataSet.View_Document, Me.Fileid_PKLabel1.Text)
AxAcroPDF1.LoadFile(OpenFileDialog1.FileName("Me.File_locationLabel1.Text"))
AxAcroPDF1.Show()
Catch ex As Exception
MsgBox(My.Settings.ERROR_msg, vbCritical, "Erreur")
End Try
No luck...I tried so many different ways..
NOTE: what i want to accomplish to upload a pdf, save pdf into a table. showing the record a a grid..double click on the grid to open a form to show all the record including any images or pdf files.
I hope I am clear on this...
thanks for your help and assistance.
|
|
|
|
|
waner michaud wrote:
AxAcroPDF1.LoadFile(OpenFileDialog1.FileName("Me.File_locationLabel1.Text")) That looks like a string, not like the value of "Me.File_locationLabel1.Text". Further, I'd be expecting to see you read it from a binary data record.
There's quite some examples on saving a binary blob; it works the same regardless of type, doesn't matter much whether it's images, PDF or anything else.
waner michaud wrote: No luck...I tried so many different ways.. Find a specific example (here on CodeProject) and gimme an exception - that'd be something that we could work from
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hey guys,
I am having a simple problem, when I add the "Threading.Thread.Sleep(5000)" line to the load event of my splash screen (at the end of the load event) it sleeps before the splash screen is fully initialized (The copyright, version number and what not) leaving big white boxes on my splash screen. I have tried adding this line to the end of the initialization code of SplashScreen 1, but that did the same thing. What am I missing?
(Basically, I want my splash screen to show for 5 seconds after loading everything).
Imports System
Public NotInheritable Class SplashScreen1
Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If My.Application.Info.Title <> "" Then
SplashScreenForm.Text = My.Application.Info.Title
Else
SplashScreenForm.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName)
End If
Version.Text = System.String.Format(Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)
Copyright.Text = My.Application.Info.Copyright
Copyright.Show()
Me.Show()
Me.Focus()
Threading.Thread.Sleep(5000)
Me.WindowState = FormWindowState.Minimized
Me.Visible = False
MenuEditorForm.Show()
MenuEditorForm.TopMost = True
End Sub
End Class
|
|
|
|
|
You can't put the Sleep in there, at all.
What you're doing is hanging the UI thread with the Sleep. The UI thread is waiting for your Load event code to finish executing before it can get back to processing the message pump. The message pump is going to have WM_PAINT messages in it waiting to be processed so your form can paint itself.
|
|
|
|
|
Thanks! Can I have it call a function that has sleep in it?
|
|
|
|
|
No because you're still on the UI thread.
The "work" should be done on a sperate thread to leave the UI thread to, well, update UI things. Look into awaiting Tasks[^] or using a BackgroundWorker[^] to move the "work" off of the UI thread.
|
|
|
|
|
i want read html data using the vbscript
|
|
|
|
|
OK, permission granted! Please, proceed.
Or did you forget to specify what you're having a problem with?
|
|
|
|
|
I want to know the script to read the html data using vb script
|
|
|
|
|
this the html code
i want to retrive 27 value from this
--Name-Failed Tests-Successful Tests-Total Tests-Success %---Payment_HealthCheck/Payment_HealthCheck.tst-27-90-117-76%-
|
|
|
|
|
So you want someone to write the code for you? Not going to happen. We don't get paid to do your work.
This[^] is where you start researching how to do web scraping in VBScript.
|
|
|
|
|
Some VB6 programs will not run in Windows 7. When I try a message appears stating "Object Library Not Registered.
What do I have to do to correct the problem?
|
|
|
|
|
Install the libraries that your VB6 code is using.
These are usually control libraries.
|
|
|
|
|
I reinstalled them but the program will not run.
|
|
|
|
|
|
I think you have to do this in your forms so the platform is recognized. Remember that SYSWOW is also going to be a location that windows will decide to run in.
#If Win64 Then
#ElseIf Win32 Then
#Else
#End If
|
|
|
|
|
Hello VB Code people,
I'm having trouble finding the correct code that when I select or multi-select an item from a list box in a Word 2007 userform and then press a button. I want it to create a table in Word 2007 from the items that I've selected in the list box. The userform gets populated from Excel and it works fine. Below is the VB Code for populating the userform with Excel data. Any help is greatly appreciated. Thank you
Private Sub Userform_Initialize()
Dim strOffice As String
Dim i As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
strOffice = "Test"
Set db = OpenDatabase("C:Testdata.xlsx", False, False, "Excel 12.0; IMEX=1;")
Set rs = db.OpenRecordset("SELECT * FROM `Test`")
ListBox1.ColumnCount = rs.Fields.Count
With rs
.MoveLast
i = .RecordCount
.MoveFirst
End With
ListBox1.Column = rs.GetRows(i)
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
lbl_Exit:
Exit Sub
End Sub
|
|
|
|
|
Hello folks,
This issue has me baffled for a few days now. I have tried everything I can possibly think of but nothing seems to work.
In this project, which is just for practice purposes, I insert data to SQL via a small form of three TextBoxes. This works fine and the data is inserted fine. The data is then shown in ComboBox Dropdown where, by selecting a value, shows related content in three other textboxes. This all works fine also.
I can delete content from a third form, which has a DataGridView and by selecting a row and clicking a button, the data is removed from SQL and also the DataGrid updates itself immediately.
The issue I am having is the ComboBox on the main form "Form1" is not updated unless I close the application and reopen it again. I was told on another site that I would need to "Fill the Dataset again". But have no clue what they meant or how that is done.
I tried a few suggestions that I had found on a Google Search but alas, nothing works, such as Form1.Refresh, ComboBox1.Refresh etc.
Here is my code for deleting, which is in the DeleteEntry.vb form:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myconnect As New SqlClient.SqlConnection
myconnect.ConnectionString = "Data Source=.\INFLOWSQL;Initial Catalog=RioDiary;Integrated Security=True"
Dim mycommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
mycommand.Connection = myconnect
myconnect.Open()
Try
mycommand.CommandText = "DELETE FROM MyDiary WHERE Title = @Title"
mycommand.Parameters.Add("@Title", SqlDbType.VarChar)
For Each row As DataGridViewRow In DataGridView1.SelectedRows
mycommand.Parameters(0).Value = row.Cells(0).Value
mycommand.ExecuteNonQuery()
DataGridView1.Rows.Remove(row)
Next row
MsgBox("Data Successfully Deleted")
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message)
End Try
ds = New DataSet()
da.SelectCommand = mycommand
da.Fill(ds)
mycommand.Dispose()
Me.Close()
myconnect.Close()
End Sub
And here is Form1:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.MyDiaryTableAdapter.Fill(Me.RioDiaryDataSet5.MyDiary)
Dim con As New SqlConnection(" Data Source=.\INFLOWSQL;Initial Catalog=RioDiary;Integrated Security=True")
cmd.CommandText = "Select Title,DiaryContent,DiaryDate FROM MyDiary "
ComboBox1.Refresh()
Dim da As New SqlDataAdapter
da.SelectCommand = cmd
cmd.Connection = con
da.Fill(ds, "MyDiary")
con.Open()
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "Title"
ComboBox1.ValueMember = "DiaryContent"
End Sub
Private Sub NewEntryToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewEntryToolStripMenuItem.Click
AddEntry.Show()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If (Not Me.ComboBox1.SelectedItem Is Nothing) Then
Dim SelectedItem = TryCast(ComboBox1.SelectedItem, DataRowView)
Me.TextBox1.Text = SelectedItem.Row("DiaryDate").ToString()
Me.TextBox2.Text = SelectedItem.Row("Title").ToString()
Me.TextBox3.Text = SelectedItem.Row("DiaryContent").ToString()
ComboBox1.Refresh()
End If
con.Close()
End Sub
Would anyone please help in shedding some light on this? I have been battling my brains and searching google with three days.
Thank you in advance.
|
|
|
|
|
Dan O'Riordan wrote: and searching google with three days. You'll need to conquer the word "dataset[^]".
A dataset is a collection of in-memory DataTable[^]'s. The query that is executed returns data, and that's stored in that memory-table. You're telling the combobox where to find these values on the line below;
ComboBox1.DataSource = ds.Tables(0)
..and that needs to be filled anew when you want new values.
Dan O'Riordan wrote: The issue I am having is the ComboBox on the main form "Form1" is not updated unless I close the application and reopen it again. Things in a combobox are usually snapshots of that moment; I wouldn't expect it's contents to change while I'm navigating. Would you?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|