I am using visual basic 2012. I checked many tutorials on the net. i did exactly as were in tutorials, to add reference to directx in visual basic. but when i run my program it some times shows errors, some times it hangs, some times it doesnt shows any thing and compiles. I think in the tutorials they are using different version of visual basic, but how should i add reference to directx in visual basic, so that it runs fine? the given code should work fine because it is exact as in tutorial. i am using visual basic 2012.
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX.DirectInput
Public Class Form1
Dim runonce As Boolean = True
Dim gamerun As Boolean = True
Dim bkgcolor As Color = Color.Black
Dim d3dev As Direct3D.Device
Dim d3dpp As New PresentParameters ' = New PresentParameters
Dim drawfont As Direct3D.Font
Dim x As Int32
Dim wait As Int32
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
gamerun = False
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If (e.KeyCode = Keys.Escape) Then
gamerun = False
Me.Close()
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim pos As Point
pos.X = 0
pos.Y = 0
Me.Location = pos
Me.Height = 600
Me.Width = 800
Me.Show()
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
If runonce Then
Me.Show()
runonce = False
init()
run()
End If
End Sub
Private Sub init()
d3dpp.DeviceWindow = Me
d3dpp.BackBufferCount = 1
d3dpp.BackBufferFormat = Format.X8R8G8B8
d3dpp.BackBufferHeight = Me.Height
d3dpp.BackBufferWidth = Me.Width
d3dpp.SwapEffect = SwapEffect.Discard
d3dpp.PresentationInterval = PresentInterval.Immediate
d3dpp.Windowed = True
d3dpp.EnableAutoDepthStencil = True
d3dpp.AutoDepthStencilFormat = DepthFormat.D24S8
d3dev = New Direct3D.Device(0, Direct3D.DeviceType.Hardware, Me, CreateFlags.HardwareVertexProcessing, d3dpp)
drawfont = New Direct3D.Font(d3dev, New System.Drawing.Font("IMPACT", 32, FontStyle.Regular, GraphicsUnit.Pixel))
x = 25
wait = 0
End Sub
Private Sub run()
Do While gamerun
d3dev.Clear(ClearFlags.Target, Color.Black, 1, 0)
d3dev.BeginScene()
drawfont.DrawText(Nothing, "TEST", x, 50, Color.DarkCyan)
d3dev.EndScene()
d3dev.Present()
Windows.Forms.Application.DoEvents()
Loop
End Sub
End Class
The DirectX SDK's only support for Visual Basic .NET is the legacy Managed DirectX 1.1 assemblies. These have not been updated in a very long time, and since they are based on .NET 1.1 they won't work with .NET 4.0 or .NET 4.5. They only work with .NET 2.0/3.x. VB 2012 uses .NET 4.5.
You should consider looking at an alterative like SlimDX or SharpDX.
See DirectX and .NET.
Related
I have an excel sheet having 2 columns. Now i want that all values of column 1 should be stored in one list lets say ListTime and all values of column 2 should be stored in another list lets say ListAcceleration. I dont know how to do this.
Thanks in advance.
this is a good way:
Imports Microsoft.Office.Interop
Imports Microsoft.WindowsAPICodePack.Dialogs
Public NotInheritable Class FormMain
Private xlApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
Private xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Private ListTime As New List(Of Double)
Private ListAcceleration As New List(Of Double)
Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles ButtonStart.Click
Dim Path As String
Using OFD1 As New CommonOpenFileDialog
OFD1.Title = "Exceldatei auswählen"
OFD1.Filters.Add(New CommonFileDialogFilter("Excel", ".xlsx"))
OFD1.IsFolderPicker = False
OFD1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If OFD1.ShowDialog = CommonFileDialogResult.Ok Then
Path = OFD1.FileName
Else
Return
End If
End Using
xlWorkBook = xlApp.Workbooks.Open(Path)
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet = CType(xlWorkBook.Worksheets("Tabelle1"), Microsoft.Office.Interop.Excel.Worksheet)
Dim xlRange As Microsoft.Office.Interop.Excel.Range = xlWorkSheet.UsedRange
Dim ER As Microsoft.Office.Interop.Excel.Range
For rCnt As Integer = 1 To xlRange.Rows.Count Step 1
ER = CType(xlRange.Cells(rCnt, 1), Microsoft.Office.Interop.Excel.Range)
ListTime.Add(CDbl(ER.Value))
ER = CType(xlRange.Cells(rCnt, 2), Microsoft.Office.Interop.Excel.Range)
ListAcceleration.Add(CDbl(ER.Value))
Next
xlWorkBook.Save()
xlWorkBook.Close()
xlApp.Quit()
If xlWorkSheet IsNot Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet)
If xlWorkBook IsNot Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook)
If xlApp IsNot Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
xlApp = Nothing
xlWorkBook = Nothing
xlWorkSheet = Nothing
End Sub
Private Sub FormMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
If xlWorkBook IsNot Nothing Then xlWorkBook.Close()
If xlApp IsNot Nothing Then xlApp.Quit()
End Sub
End Class
There are just a few things you need to consider: First you have to download the “Microsoft.Office.Interop.Excel” package from Visual Studio's own NuGet package manager. Also the package “Microsoft.WindowsAPICodePack.Dialogs” to have a reasonable OpenFileDialog.
In the case of MS Office files, it is important to release the file using System.Runtime.InteropServices.Marshal.ReleaseComObject(..), otherwise you cannot edit it later when you click it on your desktop. In that case you would have to restart the PC. So don't forget. 😉
Oh and by the way: This word – in my case “Tabelle1” – will be named differently in your language. You have to change this.
i am very new to VB.net and i'm trying to proceed step by step with my application.
The application i'm trying to build will collect a series of macros i've written in Excel VBA environment.
Now, the following code pasted below, is the initial part, where basically i try to load a workbook (to be used as Active workbook) and to "unload it".
The issue comes when, after "unloading" the workbook, i try to open the very same workbook in excel.
Excel application return an error that is "Open in read-only". This cannot be accepted, and i need to understand how to unload the workbook and release it from the myAPP.
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim workbook As Excel.Workbook
Dim worksheet As Excel.Worksheet
Dim APP As New Excel.Application
Private Sub opn_btn_Click(sender As Object, e As EventArgs) Handles opn_btn.Click
Dim strname As String
Dim cellname As String
With OpenFileDialog1
.InitialDirectory = "E:\Vs_Excel"
.Title = "Open xlsx file"
.ShowDialog()
End With
workbook = APP.Workbooks.Open(OpenFileDialog1.FileName)
worksheet = workbook.Worksheets("sheet1")
cellname = worksheet.Range("A1").Value
strname = OpenFileDialog1.FileName
Me.TextBox1.Text = strname
Me.TextBox2.Text = cellname
Dim lvwReport As View = View.List
With Me.ListView1
.GridLines = True
.View = lvwReport
.CheckBoxes = True
End With
'LoadListView() 'thi sroutine is written but not used yet. Must solve first the problem wioth closing ExcelApplication
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
workbook.Close()
APP.Quit()
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
ReleaseObject(worksheet)
worksheet = Nothing
ReleaseObject(workbook)
workbook = Nothing
ReleaseObject(APP)
APP = Nothing
End Sub
Private Sub ReleaseObject(ByVal obj As Object)
Try
Dim intRel As Integer = 0
Do
intRel = System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
Loop While intRel > 0
MsgBox("Final Released obj # " & intRel)
Catch ex As Exception
MsgBox("Error releasing object" & ex.ToString)
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
End class
I've got a simple test app to demonstrate, it must be environment in some way as the complied app works on other pc's but not mine ! The research i've done has suggested uninstalling VS2015 which I've done but still not working.
here's the code
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xls As New Excel.Application
Dim book As Excel.Workbook
Dim sheet As Excel.Worksheet
xls.Workbooks.Add()
book = xls.ActiveWorkbook
sheet = book.ActiveSheet
sheet.Cells(1, 1) = "Some Text"
sheet.Cells(1, 2) = "More Text"
xls.Workbooks.Close()
xls.Quit()
releaseObject(sheet)
releaseObject(book)
releaseObject(xls)
MsgBox("Worked", MsgBoxStyle.Information)
End Sub
Private Sub releaseObject(obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
MessageBox.Show("Exception Occured while releasing object " & ex.ToString())
Finally
GC.Collect()
End Try
End Sub
End Class
it falls over on the... sheet.Cells(1, 1) = "Some Text"
Now that i've uninstalled VS2015 I'm using the compiled app above to prove my machine (which is still failing) works once i find the right fix.
But I'm struggling to work out what to do next ? I really don't want to have to wipe my machine if I can avoid it.
Okay i tried everything searched google, tried the example in docs Awesomium and it didn't work. I have a tabbed browser. How can i make for every webcontrol to handle showcreatedwebview event.
this for window you created
Private Sub Mainwindow_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PictureBox2.Enabled = False
TextBox1.Text = Clipboard.GetText
WebControl1.Source = New Uri(TextBox1.Text)
End Sub
this for you browser
Private Sub WebControl1_ShowCreatedWebView(ByVal sender As Object, ByVal e As Awesomium.Core.ShowCreatedWebViewEventArgs) Handles WebControl1.ShowCreatedWebView
Clipboard.SetText(e.TargetURL.ToString)
Dim webControl As Awesomium.Windows.Forms.WebControl = TryCast(sender, Awesomium.Windows.Forms.WebControl)
Form1.Tabcontrol1.TabContainer.AddTab(New Mainwindow, True, Form1.Tabcontrol1.TabContainer.TabCount)
Dim webControl11 As WebControl = TryCast(sender, WebControl)
If webControl Is Nothing Then Return
If Not webControl.IsLive Then Return
Mainwindow.Close()
If e.IsPopup AndAlso (Not e.IsUserSpecsOnly) Then
' JSWindowOpenSpecs.InitialPosition indicates screen coordinates
ElseIf (e.IsWindowOpen OrElse e.IsPost) Then
Else
e.Cancel = True
Mainwindow.TextBox1.Text = e.TargetURL.ToString
' Show the window.
Form1.Tabcontrol1.TabContainer.AddTab(New Mainwindow, True, Form1.Tabcontrol1.TabContainer.TabCount)
End If
End Sub
End Class
I have a user form with three comboboxes and one text box that I would like to populate with named ranges or public variables. I am working in Excel 2010 on Windows. Here is what I have:
First I run through some code that converts one worksheet into a new configuration. I then call the userform which will set up the variables necessary to update the worksheet further. I have done this on a Mac and it works, but I am transitioning this from the mac to a windows server. I thought this would be the easy part but it in not working for some reason.
Here is the code for the userform.
Public KorS As String
Public ActivityID As String
Public Stage As String
Public varsaveme As String
Private Sub ufStageDt_Initialize()
AD = varsaveme & ".xls"
duh = KorS
Set Me.tbAdName.Text = duh
Set UserForm1.Caption = AD
'Set Me.cmbLowDt.List = "AnnDt"
Set Me.cmbHighDt.List = "AnnDt"
Set Me.cmbStage.List = "Stage"
Me.cmbLowDt.List = "AnnDt"
End Sub
The public variables are present in the code on the worksheet.
Here is the code that I used on the Mac.
Private Sub UserForm_Initialize()
Ad = varsaveme & ".xls"
duh = KorS
tbAdName.Text = varsaveme
UserForm.Caption = Ad
cmbLowDt.List = Range("AnnDt").Value
cmbHighDt.List = Range("AnnDt").Value
cmbStage.List = Range("Stage").Text
End Sub
Any assistance would be greatly appreciated. I am using the ufStageDt.Show command in the vba script to bring up the userform.
Set won't work, so eliminate that. Also, List expects an array. For a single hard-coded item, use Additem.
Me.cmbHighDt.Additem "AnnDt"
EDIT: "AnnDt" is a named range:
Me.cmbHighDt.List = Application.Transpose(ActiveSheet.Range("AnnDt"))
EDIT2: For dates:
Private Sub UserForm_Initialize()
Dim i As Long
With Me.cmbHighDt
.List = Application.Transpose(ActiveSheet.Range("AnnDt"))
For i = 0 To .ListCount - 1
.List(i) = Format(.List(i), "yyyy-mm-dd")
Next i
'to get it back to a date
ActiveSheet.Range("B1") = DateValue(.List(0))
End With
End Sub