How to clear an Image in a Userform? - image

I have a Userform in which I use an Image control. I display a picture in this control, based on two criteria.
I don't know how to clear this Image in the Userform when I want to type two new criteria.

You can easily 'clear' your UserForm Image control (e.g. Image1) via Image1.Picture = LoadPicture(vbNullString). In the example below you would switch between showing a defined picture and displaying the empty control when clicking your command button. In order to control the Image status (empty or not) you check the image picture property via If Image1.Picture Is Nothing Then...
Code example in userform module (Excel)
Option Explicit
Private Sub CommandButton1_Click()
' Purpose: Change view between given image and no image
Dim sImgName As String ' picture name string
sImgName = "C:\Temp\MyPicture.gif"" ' <<< choose your picture name"
With Me.Image1
If .Picture Is Nothing Then ' picture property has been cleared already
.Picture = LoadPicture(sImgName)
Else ' a picture is already displayed
.Picture = LoadPicture(vbNullString) ' clear it now
End If
End With
End Sub
Hint to use in MS Access
Note the different use in MS Access repeating #DrMarbuse 's comment as late edit:
In Access 2010, the picture is directly set by the image path. So LoadPicture() shall not be used anymore (In Excel it is required). Everything stayed the same and worked like a charm.

Related

How to get content from field

I'm totally new to Base. I have different forms but in one named F_STRUCT of them I'm trying to make a macro which will allow the user to autofill another field when he select a zipcode.
so the database looks like this.
ID_ZIP ZIP CITY
1 97425 Les Avirons
2 82289 Toto
In my forms, I have a select which allows to select the ZIP code. It's label and name is ZipCode.
So I don't really know where to find the API reference for all the methods and chill methods, I followed examples from internet.
I tried this
Sub getZip
Dim Doc As Object
Dim DrawPage As Object
Dim Form As Object
Doc = StarDesktop.CurrentComponent
DrawPage = Doc.DrawPage
Form = DrawPage.Forms.GetByIndex(0)
Toto = Form.GetByName("ZipCode")
Print "hey"
End Sub
But it returns an error on the Toto = Form.GetByName("ZipCode") line.
The code works, so the problem must be how you created the form or control. Follow these instructions to set up a correct example:
Create Form in Design View
Use the List Box tool (is that what you mean by "select"?) and create a control.
Cancel out of the wizard if it pops up.
Right-click on the control and select Control Properties (not Name, which would modify the shape name instead of the control's name).
Set the Name to "ZipCode" (without quotes).
Save and close the form.
Open the form. In the window of that form (the CurrentComponent) go to Tools -> Macros -> Run Macro.
A list of documentation links for Base is at https://ask.libreoffice.org/en/question/80972/to-learn-libreoffice-base-are-there-introductions-or-tutorials/?answer=80973#post-id-80973.

How do I trap an error when OneDrive image renders file.OpenAsync error

In a project I try to give users the option to select images from their personal libraries. Nothing special as such.
This goes perfectly when the user selects the desired image from a local imagelibrary. But when images are selected from OneDrive, an error occurs, and I'm not able to trap the error. The source of the error seems to be in the file.OpenAsync method.
It seems like there may be a relation with the size of the selected image, but I cannot tell, as i'm not able to catch the error.
Here's the codesnippet (it's taken from the XAML image SDK samples in fact)
Dim picker As New FileOpenPicker With {.ViewMode = PickerViewMode.Thumbnail, .SuggestedStartLocation = PickerLocationId.PicturesLibrary}
'picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary
picker.FileTypeFilter.Add(".png")
picker.FileTypeFilter.Add(".jpeg")
picker.FileTypeFilter.Add(".jpg")
picker.FileTypeFilter.Add(".bmp")
Dim wBitMap as new WritableBitmap(200,200)
Dim file As StorageFile = Await picker.PickSingleFileAsync()
' Ensure a file was selected
If file IsNot Nothing Then
Try ' Set the source of the WriteableBitmap to the image stream
Using fileStream As IRandomAccessStream = Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
Await wBitmap.SetSourceAsync(fileStream)
wBitmap.Invalidate()
vwImage.Source = wBitmap
End Using
Catch e1 As TaskCanceledException
' The async action to set the WriteableBitmap's source may be canceled if the user clicks the button repeatedly
End Try
End If
As you can see, there is a try-catch in place, but nonetheless a non-trapped error pops up, and stepping through, I can detect that it happens in the line
Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
Now my question is: how do I catch this error? Am I right that the line above is the source of the error? And if not so: what is and how to overcome?
After a lot of experimenting, I think I found the solutoion.
When a StorgeFile is selected to be used as the source for an image, it is wise to check the StorageFile.Attributes.
Files that are selected will carry an Attributes value. In the case of a file from OneDrive, the Attributes value was 544 (the value that you get when combining Archive and LocallyIncomplete. So that file has to be downloaded first, and then it will be available to use.
This is explained here:
Link to the MSDN documentation on StorageFile.Attributes

Display a different image on combo box change in Access without file paths

I am creating a form that contains a combo box, lets say it's called 'Postcode_cb'. I want to have a unique image displayed for each of the items in that combo box. The images have to be in the same position and replace each other when the combo box is changed so that there is only ever 1 image. This has to be done without the use of file paths.
For example:
Try this way: create table [tblImg]([id], [picture]) where [id] is long and [picture] is OLE.
Insert two records with id=1 and id=2, embed corresponding images into [picture] field.
Then create stanalone form [frmImages] with rowsource [tblImg] and put 'bound object frame' with control source [picture].
Put [frmImages] as sub form at your main form.
Set LinkMasterFields to [Postcode_cb] and LinkChildFields to [id].
I have something like this on a database that gives out star rating of hotels. As you browse through the hotels it displays actual stars depending on the rating. The way that i did this was placed all the images in 1 spot (Placing them on top of one another) Give each image a name. and set them all to visible = no.
Example Img1, Img2 etc. until all images have a name.
Then open Visual basic and create a sub called Private Sub Form_Current() if you don't already have one. Then under this sub use the following Code
Forms![FormName]![ComboBoxName].SetFocus
Select Case Forms![FormName]![ComboBoxName].Text
Case Is = ""
Forms![FormName]!img1.Visible = False
Forms![FormName]!img2.Visible = False
Case Is = "1"
Forms![FormName]!img1.Visible = True
Case Is = "2"
Forms![FormName]!img2.Visible = True
End Select
This is only good if you only have something like 5 to 10 images anything more would be a lot harder to deal with in this way.
There maybe other ways people can suggest i found this the most easiest for my needs.

Comparing Data In Text Boxes in Visual Studio 2013

So I mostly use Microsoft Excel for a lot of my work and the most "Programming" I do is writing basic logical functions in excel.
I am setting up a windows form in Visual Studio 2013 and I want to the end user to be able to be able to confirm that the data they input into TEXTBOX1 matches what is in TEXTBOX2.
So normally in excel I can just write =IF(C2=D2,"Yes","No")
So basically I want to be able to input data in the carton field and then in the label field and if it matches I want it to say yes in the text box at the bottom.
I tried writing
If CartonBarcode = LabelBarcode Then
PartCheck = "Yes"
Else : PartCheck = "No"
End If
but that hasn't worked - I am very new to VB so please be gentle.
Eventually I also want to be able to append the scanned data (If the two text boxes match) into an excel spreadsheet.
Thanks in advance for all your help =)
Thanks for your help Mark - that makes a lot of sense.
I added this IF Statement to the PartCheck text box but it doesn't seem to display Yes or No regardless of what I put in.
It now throws two errors (look to be the same error on each line.)
Value of type 'String' cannot be converted to 'System.Windows.Forms.TextBox'
Any further help you can provide would be fantastic
Screenshot of errors
I then changed PartCheck = "Yes" to PartCheck.Text = "Yes" and it runs but then nothing displays in the PartCheck Text Box
In WinForms, TextBox and other GUI components (e.g. Label, Button) are objects, with properties and methods to interact with them. If you want to compare the text that has been entered into two TextBox objects, you will need to compare their Text properties. e.g.
Update
Updated code below based on your updated question. You are correct that you need PartCheck.Text = "Yes" to set it correctly. Your current issue is when you are performing the check. You are handling the TextChanged event for your PartCheck TextBox, but your logic should really be triggered when either the CartonBarcode or LabelBarcode text is changed. You can either have TextChanged handlers for both of those TextBox controls, and call a common subroutine to perform the check, or have a common TextChanged handler, as shown below:
Private Sub Barcode_TextChanged(sender As Object, e As EventArgs) _
Handles CartonBarcode.TextChanged, LabelBarcode.TextChanged
If CartonBarcode.Text = LabelBarcode.Text Then
PartCheck.Text = "Yes"
Else
PartCheck.Text = "No"
End If
End Sub

MS Access VBA: how do I clear Image control?

I have an Image control that reads a file from disk as the user navigates. If there is no file (an empty field), I need to erase the previous image. The microsoft page says to do as follows:
Sub Form_Click ()
picture1.picture = LoadPicture()
End Sub
But when I do it, Access complains that "the argument is not optional"! I also tried LoadPicture("") as stated here and here, to no avail. It says "Microsoft Access can't open the file '0'." How can I clear the picture in runtime? I'm using Access 2002. Thanks in advance!
Use the following:
picture1.picture = ""

Resources