this is my first post here in stackoverflow,but I followed too much about my favourite vb.net articles...
now I want to share my little experience and ask another one that I can't do...
I have precompiled pdf file with some field, textbox and checkbox. My goal is after user filling, open the pdf file with my software that can read text value from textbox and state form check box. The first is done, check the following code:
Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.xml
'open file dialog code...
Dim pdfTemplate As String = lbl_file.Text
Dim readerPDF As New PdfReader(pdfTemplate)
Dim name As Object = readerPDF.AcroFields.GetField("name")
Try
txt_name.Text = name
Catch Ex As Exception
End Try
This part of code, search a textbox called "name" and put here text proprieties into my text box. WOW...but to check a checkbox state?do you have any idea please? Thank's in advance for all.
maybe i found a way to do...check this and, what do you think about?
Dim male As Object = readerPDF.AcroFields.GetField("male")
If male = "On" Then
cmb_male.Checked = True
End If
I saw in acrobat default output value from checkbox is "On" than is enough check it and change checkbox value as needed.
Related
Hello I am very new to Visual Basic and have almost no clue what I am doing. I have encountered an issue saying the following.
openFileDialog1 is not a member of windowsapp1.my
I can not seem to fix it. Here is my code:
Public Class Form1
Private Sub Form1_Load()
Dim OpenFileDialog1 As New OpenFileDialog
My.openFileDialog1.Title = "Please select a DB file"
openFileDialog1.InitialDirectory = "C:\"
openFileDialog1.Filter = "DB Files|*.extensionHERE"
End Sub
End Class
I have tried to no avail to fix this and so I hope that some one can help, thanks!
I think you're mis-reading what the examples are saying. When you read tutorial/example code, where it lists "OpenFileDialog1," for example (or DataGridView1, etc.) that refers to whatever name you are using for your particular OpenFileDialog1 control. If you had multiple openfiledialogs in your code, having them all named OpenFileDialogN can get confusing it a larger application. Using a meaningful name is a good practice.
Using the "My" isn't necessary in your code snippet. In VB, the "My" refers to a namespace indicating the system on which the application runs. Since all your code is doing is opening a file dialog, that isn't necessary.
Check out this handy doc by MS: https://learn.microsoft.com/en-us/dotnet/visual-basic/developing-apps/development-with-my/index
I'm learning VS VB, so please forgive the ignorance.
I have built a form that accepts a file search pattern, searches for matching files and then displays the file names (up to 10) in text boxes.
If you double click on the file name (up to 10) text box, I want it to call a routine to open Powerpoint and display the first slide.
I've searched around and can't find any information thats helpful to me for 2017.
At this point, my code looks like below (just shows that I have the full file name).
Public Sub DisplaySong(ByVal SongFileName)
Dim SongToDisplay As String = ""
Dim i As Integer
' get the full song path/name
Try
Dim strFiles As String() = Directory.GetFiles(strSearchPath.ToString, SongFileName.ToString, IO.SearchOption.AllDirectories)
i = 0
' should never be more than 1 song
For Each SongFileName In strFiles
SongToDisplay = strFiles(i)
i = i + 1
Next
Catch ex As Exception
MessageBox.Show("Error processing Display Song: Finding Song!! ")
End Try
MessageBox.Show("Song Selected: " + SongToDisplay.ToString)
End Sub
The examples I've talk about adding the COMs, but I don't see "Microsoft Graph Object Library" in the 2017 version. I selected MS PowerPoint and the MS Graph 14.0, thinking (hoping) that's what I needed.
When I add
Dim oApp as PowerPoint.Application
into the subroutine, I get the error message that it's not defined. I know how to do this in Access VB 2010, but I don't know how to do this in VS VB 2017.
Any help is appreciated.
Dummy me. Adding
Imports Microsoft.Office.Interop
Fixed the problem.
I was wondering if there is anyway to get the file path of a selected file. I have registered a hotkey in reference to this.
E.g. RegisterHotKey(Me.Handle, 100, MOD_CONTROL Or MOD_SHIFT, Keys.D2)
Which will do certain actions on pressing ctrl, shift and 2. What i want to do is to get the path of a selected file WITHOUT opening OpenFileDialog
e.g. i select mydoc.doc located on my desktop, press ctrl shift and 2, and it will msgbox out the location of the file.
(meaning i click the file mydoc.doc on my desktop, press my hotkey and get the file location. Is there anyway to do this? (Just like how you would click a file in a folder to copy and paste it to another location, i want to click the file press my hotkey and msgbox out its location))
Is there anyway to do this or any direction anyone can point me in?Because i can't find any API which does this...
Thanks!
EDIT:
After reading all the updates and the several links here and there, I started to construct my own function for this, I'm just at the part to determine how many selected icons there are, but i keep getting back 0 icons is there something wrong with what I'm doing?
Public Function getDesktopFiles() As String
Dim vhandle As IntPtr = FindWindow("Progman", "Program Manager")
vhandle = FindWindowEx(vhandle, IntPtr.Zero, "SHELLDLL_DefView", vbNull)
vhandle = FindWindowEx(vhandle, IntPtr.Zero, "SysListView32", "FolderView")
Dim vItemcount As IntPtr
vItemcount = SendMessage(vhandle, LVM_GETSELECTEDCOUNT, 0, 0)
Return vItemcount
End Function
This question has a link to a Raymond Chen blog post which will give you the API calls you require, you will need to convert it to VB but it is based on COM so should be easy. The other answer to that question gives the C# version of Raymond's code...
Edited to add specifics:
1. Include project references to Microsoft Internet Controls (to get the SHDocVw namespace) and Microsoft Shell Controls and Automation (to get the Shell32 namespace)
2. Use SHDocVw.ShellWindows to get an enumeration of open browser windows.
3. Try to cast each item as a ShellBrowserWindow, and then try to cast the Document property as a Shell32.IShellFolderViewDual2 object.
4. The FocusedItem property gives the selected item.
VB.NET code:
Dim windows As New SHDocVw.ShellWindows
For Each window As Object In windows
Dim browser As SHDocVw.ShellBrowserWindow = window
Dim folder As Shell32.IShellFolderViewDual2 = browser.Document
Console.WriteLine(folder.FocusedItem.Path)
Next
I have a OpenFileDialog and its MultiSelect property is ON. My question is how can I limit the number of items to be selected, for example 5 items only?
Thanks
You can use the FileOk event to check the file(s) selected by the user when he clicks the OK button. If you are not happy then display a message and set the CancelEventArgs.Cancel property to True to prevent the dialog from closing. Like this:
Dim dlg As New OpenFileDialog()
dlg.Multiselect = True
AddHandler dlg.FileOk, Sub(s, ce)
If dlg.FileNames.Length > 5 Then
MessageBox.Show("Please select no more than 5 files")
ce.Cancel = True
End If
End Sub
If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
'' etc...
End If
You cannot. But you have alternatives:
1.- A good alternative could be to put all file names in a text file, and then accept that text file as your program's input.
2.- You should allow user to pick the directory. Then you list all the files and let them select as many files, there will not be any problem.
3.- You may have to use a FolderBrowserDialog instead and then use IO.Directory.GetFiles, which works properly.
There is no built-in feature for that in OpenFileDialog as far as I can see. Possible solution is to check FileNames returned from the dialog. If it count more than 5, for example, alert user and stop without operating the files.
How do I bold a certain word in the caption of a Microsoft Access label?
If it helps, the text itself is stored in a Microsoft Access table.
An example is below. I have a Microsoft Access form with a label, in the Form_Load() event I set the caption property of this label to the value returned in a DLookup query like so:
Private Sub Form_Load()
Me.Label0.Caption = DLookup("Field1", "Table1", "[ID] = 1")
End Sub
My text is as follows:
The quick brown fox jumps over the lazy dog
I want to embolden the word Lazy. Is this possible? If so, how do I do this?
Thanks
You do not mention the version of Access, for 2007 (AFAIK) and 2010, you can create a textbox and set the Text Format on the data tab to Rich Text. You can then set the Control Source to:
="The quick <b>brown</b> fox"
Change a few more properties, such as Locked and Enabled and you will have a textbox that looks and acts like a label.
How bad do you want this? Because I have a really crazy answer, but it might work.
Replace your label with a Web Browser Control, create a temporary html file, then point the Web Browser to that. You'll need to add a field to the underlying table (or at least I did) because the control has to be bound or you can't change the ControlSource - I think.
I put a Web Browser control on a form, turned scrollbars off, and generally tried to make it look like a label. I didn't have complete success with that, but maybe you're better at it than me.
I added a Text field to my table called "FakeLabel". The Web Browser control source should point to that field.
For purposes of testing, I put a commandbutton on the form with this code
Private Sub Command113_Click()
Dim sFile As String
Dim lFile As String
sFile = Environ("TEMP") & "\fakelabel.html"
lFile = FreeFile
Open sFile For Output As lFile
Write #lFile, "The <strong>quick</strong> brown fox jumped over the <em>lazy</em> dog"
Close lFile
Me.Recordset.Edit
Me.Recordset.Fields("FakeLabel").Value = sFile
Me.Recordset.Update
Me.WebBrowser112.Requery
End Sub
Here's what it looks like after I click the button. If you can get rid of that top padding, it could really look like a label.