I am switching a vb.net form over to the Universal windows app format and have gotten stuck with switching the PictureBox control. The code in the form format is as follows.
Sub DisplayDie(die As PictureBox, face As Integer)
die.Image = Image.FromFile(FILE_PREFIX & face & FILE_SUFFIX)
End Sub
Well there are a lot of new concepts you will need to learn before to switch your code I think your code is from Windows Forms.
First of all there are somethings to know before:
You can't access directly to the folders of the user( C:/ or C:/MyFolder)
You need to enable some special capabilities to access to Documents library , Pictures library
https://msdn.microsoft.com/en-us/library/windows/apps/hh464936.aspx#special_capabilities
You need to use FileOpenPicker to let the user select some image
https://msdn.microsoft.com/library/windows/apps/br207847?cs-save-lang=1&cs-lang=vb#code-snippet-1
Finally you will get a stream.
Here is an example how to use it
http://www.c-sharpcorner.com/UploadFile/mahesh/open-file-using-fileopenpicker-in-windows-store-app/
this code is in C# but is very easy to understand.
Related
As usual, I do my research in the various forums. My personal discipline is that if I have struggled for more than a day, I need to reach out for help. Because after a day, I can no longer see the wood because of the trees.
My web site has some code written in VB.NET which I use on many pages of the web site. Where possible, I try to write code only once. For obvious reasons. I include the code in a class.
However, when I use a class, I cannot access the page controls. For example, the HTTP context is available on the VB.NET code-behind but not in the class declared in the code-behind. Is there some way of achieving this result?
Another option is to have VB.NET code in a separate source file. And to include this source file into the main source code file at compile time. If I need to make a change, I can do it in the source code
“segment” once only. Right now, if I want to make a global change, I have to cut and paste through many web pages. I have read that this type of “include” was possible in VB prior to VB.NET. I can find no reference to this for VB.NET in Visual Studio. Any suggestions?
For example if this code is to be run on every web page, how would you set it up so that you only have one source? That is called on 150 pages?
Protected Sub getCookieVariable()
'
Dim myCookieName As String
Dim myCookieValue As String
'
myCookieName = "hfl3"
Dim myCookie As HttpCookie = HttpContext.Current.Request.Cookies(myCookieName)
If Request.Cookies(myCookieName) IsNot Nothing Then
myCookieValue = myCookie.Value
myCookie.Expires = DateTime.Now.AddDays(30)
Response.Cookies.Add(myCookie)
session("myCookieValue") = myCookieValue
End If
'
End Sub
How can I return a message box with functioning HTML tags using VBA?
example
dim mtext as string
mtext = "<em>hello</em> <br> world"
msgbox mtext
You don't. The MsgBox function is just a thin wrapper over a Win32 API function, and that function doesn't deal with HTML input. HTML is for web browsers, not desktop applications.
The closest thing you could get is a custom UserForm with a RichTextBox control, but that's OCX tech developped for Visual Basic 6.0 and probably won't work on x64 machines, not to mention that it will definitely break down if you need to distribute your macro to users that don't have the OCX on their machines.
A better alternative could be to make a COM-visible class library in your favorite .NET language (C#, VB.NET), and expose a custom MessageBox function that displays a WinForms dialog featuring a System.Windows.Forms.RichTextBox control that can process and display RTF formatted text.
You then need to distribute and register your COM type library to your users.
In other words, it can be done - it only depends how badly you want it.
I would custom design a form and then have the text set based on your needs specifically. May I ask why you are wanting to use HTML codes? Cause, it may be simple enough to create your own library/class to handle the processing, before pushing to a rich text box. However, the Rich Text Box is only going to be in VB, like using VB Studio Express. With VBA, you're sort of stuck...sorry.
I have a PDF COM control on a Windows Forms Application. The process is simple, a file path is sent to a Sub, it checks if the file exists and if so, loads the file on my PDF control and shows the form. The code is simple:
Public Sub LoadPDF(ByVal pathPDF As String)
MessageBox.Show(pathPDF)
If System.IO.File.Exists(pathPDF) Then
frmPDF.dePDF.LoadFile(pathPDF)
frmPDF.Show()
Else
MessageBox.Show("No image available. Please check FEMA and CAMSIS.")
frmPDF.Hide()
End If
End Sub
This code worked 2 hours ago. The same code still works in other applications (that pull the exact same file path). I have compared designer codes/control properties/etc between the current application and the others. I can't find a difference at all. I have tried completely recreating the form and COM control.
Does anyone know why this may be happening?
My solution:
The reference .dll files were corrupt. I used the solution here C# System.AccessViolationException and System.Runtime.InteropServices.SEHException
to fix it. Everything seems to be running fine for now.
Use this instead
axAcroPDF1.src = PDFPath;
To load your PDF into the control instead of LoadFile.
I have about 100 sub routines that I need to use..I am going to be calling them into a web browser component do get some elements after each web page has completed.
Is it possible to create one sub routine and then has say a streamreader loop through a folder and read each text file in the folder to put the sub into a string?
I would then simply call that one sub into the webbrowser component but I didn't know if this was possible?
There would be about 100 different text files in the folder.
The thinking behind this would be that if I wanted to add more website instructions to the sub or take away from the sub I could just delete a text file.
How would one begin this crazy journey?
Thanks
That isn't really something you would want to do. Its also not possible since vb.net is a compiled language it can't just read the text of the code on the fly and implement it like that.
You are better off investigating another pattern that will meet your needs.
Actually you can programmatically create a vb.net program on the fly. I created a web program which rewrites itself as I see fit. Part of that code adds new subroutines to the same vb.net program. Basically writing more sub routines to itself and then it runs itself again. You can easily store your other subs into txt files and then recall the data later if you wanted. The trick here, however, is that you have to first add the sub routines into an entirely new file, then, when all the writing is done, you can then preform the following:
File.Delete(Server.MapPath("your old file name"))
File.Copy(Server.MapPath("your new file name"), Server.MapPath("your old file name"))
It should be noted that I make web applications, so it doesn't quite work the same. Using asp.net pages, the way I get the new program to run with the new sub routines is to run on the client side code, in which I include a little timed refresh, which fires once the rewriting task is finished. The page then refreshes with the new vb.net back end code in place.
In order to do this for a desktop application or whatever might require something else which I am not aware of.
OKay, I'm from a PHP background, but I've just been tasked with developing some custom Web Parts in SharePoint. I've figured out how to create and deploy a basic "Hello world" web part in VB. Okay so far.
What I'm stuck on is a really basic, stupid point - how the hell do I lay out things in a VB web part?
For an example, here's a label and a textbox:
protected overrides sub createchildcontrols()
mybase.createchildcontrols
dim mylabel as new label
dim mytextbox as new textbox
mylabel.text ="My label text"
mytextbox.text ="My textbox"
me.controls.add(mylabel)
me.controls.add(mytextbox)
How would I, for example, get mylabel and my textbox to appear on different lines, rather than running one after the other as they do now? In PHP I'd just wrap them in some top break them onto differnt lines, but how do I do it here?
There are a number of ways to go about it. The easiest, if you really just want the controls to appear on different lines would be to add an ASP.net LiteralControl with a BR tag between them.
Aside from that, you can always use the ASP.net formatting controls, like Table to break your controls into sections for output.
Additionaly, everything that derives from WebControl has an Attribues and CssClass property for setting formatting based on style-sheets you can use.
The last method, and the most customizable, but hardest to maintain and change, would be to override the webpart's Render method and generate your HTML completely by hand in the WebPart.
Alternately, you could scrap this altogether, and employ the SmartPart to develop ASP.net user controls for use inside of SharePoint, giving you the options to use the Visual Studio designer tools to layout your controls on the form.
You should override the Render() method. By default this method just renders all the child controls you have added in the CreateChildControls() method, but overriding it lets you write additional HTML elements around the controls.
I usually code in C#, but I think the following example should work in VB:
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.Write("<h1>Custom webpart rendering</h1>")
me.mylabel.RenderControl(writer)
writer.Write("<br />")
me.myTextbox.RenderControl(writer)
End Sub
Give it a try...
I've been developing web parts for an ASP.NET site using the standard web user control model, which gives you access to the VS designer and means your UI can be standard HTML. ASP.NET then wraps the UserControl into a GenericWebPart at runtime to host it in a WebParts site.
I know that Sharepoint doesn't support this model out of the box but I've just found this which might help you...
http://weblogs.asp.net/jan/archive/2006/12/02/announcing-the-return-of-the-smartpart.aspx
Smart Part (or a variation of it) is the easiest way to go. Why mess with rendering direct html when you can develop a user control more easily?
Plus if you are not an expert in VB, having Visual Studio Designer will help with creating user controls
i blogged about this very topic. Easily build a rich UI for a web part without using SmartPart
Thanks for all the responses. I've gone with EvilGoatBobs solution as the most immediately easy to implement.
This is my first time on StackOverflow and your helpful answers have made it a really good introduction to the site! :)