In my VB.net (2012) program, I defined some resources. I did this by right-clicking on the project name in the Solution Explorer window and choosing properties. From there, I picked the Resources tab the Add Resources -> Add Existing File. I also have the following code:
In the class, but before any routines:
In the form’s Load routine:Code:Structure imInfo Dim strName As String Dim brPtr As Bitmap End Structure Dim aryInfo(6) As imInfo
In a button click routine:Code:aryIno(0).strName = "name1" aryIno(0).brPtr = My.Resources.name1 aryIno(1).strName = "name2" aryIno(1).brPtr = My.Resources.name2
And the routine called:Code:For t = 0 To cntImages images(t).strFName = <entered string> images(t).bm = getBMfromName(images(t).strFName) Next
The code works just fine and the aryInfo array only has seven elements and is unlikely to change. However, the manner in which I did this strikes me as being both ugly and inefficient. Is there a better/cleaner way to accomplish this?Code:Private Function getBMfromName(ByVal resName As String) As Bitmap For i = 0 To 6 If aryIno(i).strName = resName Then getBMfromName = aryIno(i).brPtr Exit Function End If Next End Function




Reply With Quote
