flash will not start automatically playing video and video advancement fails? - vb.net

I am having trouble getting my current vb.net code to start automatically playing random video trailers retrieved from trailer addicts API service (I only return 6 of them at a time). In addition, I can play the first video but other videos fail to allow me to let me play them manually too with an error about protected memory being accessed. Here's the code:
Private Sub TrailerRotateTimer_Tick(sender As Object, e As EventArgs) Handles TrailerRotateTimer.Tick
If FirstTrailer = False Then
Select Case myoptions.TrailerPlayTime
Case Is = 60
TrailerRotateTimer.Interval = 60000
FirstTrailer = True
Case Is = 90
TrailerRotateTimer.Interval = 90000
FirstTrailer = True
Case Is = 120
TrailerRotateTimer.Interval = 120000
FirstTrailer = True
Case Else
TrailerRotateTimer.Interval = 60000
FirstTrailer = True
End Select
End If
firstvideo = myoptions.TrailerUrlCollection.Item(randnum.Next(1, 5))
' Video.EmbedMovie = True
Video.AllowScriptAccess = "always"
Video.FlashVars = ""
' Video.Playing = True
Video.LoadMovie(0, firstvideo)
If Video.IsPlaying = False Then
' Video.CallFunction("<invoke name=""id"" returntype=""xml""><arguments><string>100788</string></arguments></invoke>")
Video.Play()
'Video.Playing = True
'Video.Loop = False
Else
Video.Stop()
Video.Play()
End If
End Sub
Does anyone know what I am doing wrong?
P.S. here's the direct link I found to the SWF file if needed: http://v.traileraddict.com/js/flash/player.swf?id=100788&e=y&id=100788

Related

vb.net If Else statement

I have this if else statement that I need help with.
What I would like to happen is the user enters a number in data grid view columnIndex 0. If the first validation (If CheckSatus(chkValue)) fails turn the back color red and stop. If its valid I want to continue to CheckRelease(chkValue). Right now if its invalid it goes to CheckRelease(chkValue) and change the back color yellow.
Current Code:
Private Sub gridUserEntries_CellLeave(sender As Object, e As DataGridViewCellEventArgs) Handles gridUserEntries.CellLeave
'Validate Release Number is validate and that Release is in F4 screen
If (e.ColumnIndex = 0) Then
Dim currCell As DataGridViewCell = gridUserEntries.CurrentCell
Dim chkValue As String = currCell.GetEditedFormattedValue(currCell.RowIndex, DataGridViewDataErrorContexts.Display)
If Not (chkValue.Trim = "") Then
'Validate if release is in jobscopedb.IPJOBM table
If CheckSatus(chkValue) Then
currCell.Style.BackColor = Color.White
Else
currCell.Style.BackColor = Color.Red
btnUpdatePPUSRFS.Enabled = False
btnClear.Enabled = True
End If
'Validate if the Release Number is in the PPUSRFS TABLE
If CheckRelease(chkValue) Then
currCell.Style.BackColor = Color.White
btnValidate.Enabled = True
btnRetrieve.Enabled = True
btnClear.Enabled = True
Else
currCell.Style.BackColor = Color.Yellow
btnInsertPPUSRFS.Enabled = True
btnValidate.Enabled = False
btnRetrieve.Enabled = False
End If
Else
currCell.Style.BackColor = Color.White
End If
End If
Simplify each test by only looking for the failure condition (no Else block), and then use a Return statement to stop processing. Then put the success code just once, after all the tests:
If (e.ColumnIndex = 0) Then
Dim currCell As DataGridViewCell = gridUserEntries.CurrentCell
Dim chkValue As String = currCell.GetEditedFormattedValue(currCell.RowIndex, DataGridViewDataErrorContexts.Display)
'Validate if release is in jobscopedb.IPJOBM table
If String.IsNullOrWhitespace(chkValue) Then
currCell.Style.BackColor = Color.Red
btnUpdatePPUSRFS.Enabled = False
btnClear.Enabled = True
Return ' or Exit Sub
End If
'Validate if the Release Number is in the PPUSRFS TABLE
If Not CheckRelease(chkValue) Then
currCell.Style.BackColor = Color.Yellow
btnInsertPPUSRFS.Enabled = True
btnValidate.Enabled = False
btnRetrieve.Enabled = False
Return
End If
' Add as many other tests as you need
'Made it this far means success
currCell.Style.BackColor = Color.White
btnValidate.Enabled = True
btnRetrieve.Enabled = True
btnClear.Enabled = True
End If
Even better, use a boolean so you also only need the failure code once:
If (e.ColumnIndex = 0) Then
Dim currCell As DataGridViewCell = gridUserEntries.CurrentCell
Dim chkValue As String = currCell.GetEditedFormattedValue(currCell.RowIndex, DataGridViewDataErrorContexts.Display)
'Validate if release is in jobscopedb.IPJOBM table
Dim Success As Boolean = Not String.IsNullOrWhitespace(chkValue)
'Validate if the Release Number is in the PPUSRFS TABLE
Success = Success AndAlso CheckRelease(chkValue)
' Add as many other tests as you need
If Success Then
currCell.Style.BackColor = Color.White
btnValidate.Enabled = True
btnRetrieve.Enabled = True
btnClear.Enabled = True
Else
currCell.Style.BackColor = Color.Yellow
btnInsertPPUSRFS.Enabled = True
btnValidate.Enabled = False
btnRetrieve.Enabled = False
End If
End If
Note the use of AndAlso, which short-circuits, meaning it will stop evaluating the expression as soon as it knows that logical result (when the first part is False). The CheckRelease() only runs if Success is True. We can use this to further reduce the code:
Dim Success As Boolean =
Not String.IsNullOrWhitespace(chkValue) AndAlso
CheckRelease(chkValue) AndAlso
SomeOtherTest() AndAlso
AsManyAsYouNeed()

Microsoft Excel VBA - Run-Time Error 438

I appear to be having an error which I am struggling to figure out the reason. I have tried the help sections and also tried researching it online but have not come up with any results. I am hoping someone may be able to assist me in the matter.
Issue
I have created multiple forms for different sheets on my spreadsheet. I have made forms which can be used to hide/show select column(s) by user discretion. I have two forms which work perfectly fine, but on the third.
I get
Run-Time Error 438 "Object doesn't support this property or method"
What does this mean? The code is the exact same as the other forms. The only difference in them is that the names of the sheets are different.
I will paste the code below for the sheets. Hopefully you can distinguish which is which. I will try and do my best to explain.
Code below
Main sheet - contains button to form open form
Private Sub openUserForm_Click()
chkFormCooms.Show
End Sub
Userform
Option Explicit
Sub hideCol(C As Integer)
If Controls("CheckBox" & C) = True Then
Columns(C).Hidden = True
Else
Columns(C).Hidden = False
End If
ActiveWindow.ScrollColumn = 1
End Sub
Private Sub chkP1_Click()
If Me.chkP1.Value = True Then
Sheets("Cooms").Columns("T:W").Hidden = True
Sheets("chkCooms").chk1.Value = True
ElseIf Me.chkP1.Value = False Then
Sheets("Cooms").Columns("T:W").Hidden = False
Sheets("chkCooms").chk1.Value = False
End If
End Sub
Private Sub chkP2_Click()
If Me.chkP2.Value = True Then
Sheets("Cooms").Columns("X:AA").Hidden = True
Sheets("chkCooms").chk2.Value = True
ElseIf Me.chkP2.Value = False Then
Sheets("Cooms").Columns("X:AA").Hidden = False
Sheets("chkCooms").chk2.Value = False
End If
End Sub
Private Sub chkP3_Click()
If Me.chkP3.Value = True Then
Sheets("Cooms").Columns("AB:AE").Hidden = True
Sheets("chkCooms").chk3.Value = True
ElseIf Me.chkP3.Value = False Then
Sheets("Cooms").Columns("AB:AE").Hidden = False
Sheets("chkCooms").chk3.Value = False
End If
End Sub
Private Sub chkP4_Click()
If Me.chkP4.Value = True Then
Sheets("Cooms").Columns("AF:AI").Hidden = True
Sheets("chkCooms").chk4.Value = True
ElseIf Me.chkP4.Value = False Then
Sheets("Cooms").Columns("AF:AI").Hidden = False
Sheets("chkCooms").chk4.Value = False
End If
End Sub
Private Sub chkP5_Click()
If Me.chkP5.Value = True Then
Sheets("Cooms").Columns("AJ:AM").Hidden = True
Sheets("chkCooms").chk5.Value = True
ElseIf Me.chkP5.Value = False Then
Sheets("Cooms").Columns("AJ:AM").Hidden = False
Sheets("chkCooms").chk5.Value = False
End If
End Sub
Private Sub chkP6_Click()
If Me.chkP6.Value = True Then
Sheets("Cooms").Columns("AN:AQ").Hidden = True
Sheets("chkCooms").chk6.Value = True
ElseIf Me.chkP6.Value = False Then
Sheets("Cooms").Columns("AN:AQ").Hidden = False
Sheets("chkCooms").chk6.Value = False
End If
End Sub
Private Sub chkP7_Click()
If Me.chkP7.Value = True Then
Sheets("Cooms").Columns("AR:AU").Hidden = True
Sheets("chkCooms").chk7.Value = True
ElseIf Me.chkP7.Value = False Then
Sheets("Cooms").Columns("AR:AU").Hidden = False
Sheets("chkCooms").chk7.Value = False
End If
End Sub
Private Sub chkP8_Click()
If Me.chkP8.Value = True Then
Sheets("Coomst").Columns("AV:AY").Hidden = True
Sheets("chkCooms").chk8.Value = True
ElseIf Me.chkP8.Value = False Then
Sheets("Cooms").Columns("AV:AY").Hidden = False
Sheets("chkCooms").chk8.Value = False
End If
End Sub
Private Sub chkP9_Click()
If Me.chkP9.Value = True Then
Sheets("Cooms").Columns("AZ:BC").Hidden = True
Sheets("chkCooms").chk9.Value = True
ElseIf Me.chkP9.Value = False Then
Sheets("Cooms").Columns("AZ:BC").Hidden = False
Sheets("chkCooms").chk9.Value = False
End If
End Sub
Private Sub chkP10_Click()
If Me.chkP10.Value = True Then
Sheets("Cooms").Columns("BD:BG").Hidden = True
Sheets("chkCooms").chk10.Value = True
ElseIf Me.chkP10.Value = False Then
Sheets("Cooms").Columns("BD:BG").Hidden = False
Sheets("chkCooms").chk10.Value = False
End If
End Sub
Private Sub chkP11_Click()
If Me.chkP11.Value = True Then
Sheets("Cooms").Columns("BH:BK").Hidden = True
Sheets("chkCooms").chk11.Value = True
ElseIf Me.chkP11.Value = False Then
Sheets("Cooms").Columns("BH:BK").Hidden = False
Sheets("chkCooms").chk11.Value = False
End If
End Sub
Private Sub chkP12_Click()
If Me.chkP12.Value = True Then
Sheets("Cooms").Columns("BL:BO").Hidden = True
Sheets("chkCooms").chk12.Value = True
ElseIf Me.chkP12.Value = False Then
Sheets("Cooms").Columns("BL:BO").Hidden = False
Sheets("chkCooms").chk12.Value = False
End If
End Sub
Private Sub chkP13_Click()
If Me.chkP13.Value = True Then
Sheets("Cooms").Columns("BP:BS").Hidden = True
Sheets("chkCooms").chk13.Value = True
ElseIf Me.chkP13.Value = False Then
Sheets("Cooms").Columns("BP:BS").Hidden = False
Sheets("chkCooms").chk13.Value = False
End If
End Sub
Private Sub UserForm_Initialize()
Me.chkP1.Value = Sheets("chkCooms").chk1.Value
Me.chkP2.Value = Sheets("chkCooms").chk2.Value
Me.chkP3.Value = Sheets("chkCooms").chk3.Value
Me.chkP4.Value = Sheets("chkCooms").chk4.Value
Me.chkP5.Value = Sheets("chkCooms").chk5.Value
Me.chkP6.Value = Sheets("chkCooms").chk6.Value
Me.chkP7.Value = Sheets("chkCooms").chk7.Value
Me.chkP8.Value = Sheets("chkCooms").chk8.Value
Me.chkP9.Value = Sheets("chkCooms").chk9.Value
Me.chkP10.Value = Sheets("chkCooms").chk10.Value
Me.chkP11.Value = Sheets("chkCooms").chk11.Value
Me.chkP12.Value = Sheets("chkCooms").chk12.Value
Me.chkP13.Value = Sheets("chkCooms").chk13.Value
End Sub
I hope this all makes sense and that someone is able to assist me in this matter. If you need further explanation then please do not hesitate to ask. Thank you very much for your assistance.
Check the name of your userform its probably spelt incorrectly
For information about the error check this amazing description

How to make the second event start after the first one

How to make the second event start after the first one.
Below is a code that copies files from 2 different paths set by the user for me. On the other hand, it wants to make the first copy from another path before it goes to the next one.
Public Sub StartCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartCopy.Click
' Reset variables
_stopped = False
' Create the FileCopy class which will initiate the threads
CopyFiles = New FileCopy
CopyFiles.FromPath = My.Settings.pathmemfrom1
CopyFiles.ToPath = My.Settings.pathmemto1
' Initiate the copy, count from the FileCopy class
CopyFiles.StartCopy()
WorkingBar.Minimum = 0
WorkingBar.Maximum = 100
WorkingLabel.Visible = True
WorkingBar.Visible = True
' Reset form controls
setting.Panel.Enabled = False
StopCopy.Enabled = True
ViewLog.Enabled = True
CopyFiles.Dispose()
'Reset veriables
_stopped = False
' Create the FileCopy class which will initiate the threads
CopyFiles2 = New FileCopy
CopyFiles2.FromPath = My.Settings.pathmemfrom2
CopyFiles2.ToPath = My.Settings.pathmemto2
CopyFiles2.StartCopy()
WorkingBar.Minimum = 0
WorkingBar.Maximum = 100
WorkingLabel.Visible = True
WorkingBar.Visible = True
' Reset form controls
setting.Panel.Enabled = False
StopCopy.Enabled = True
ViewLog.Enabled = True
CopyFiles2.Dispose()
'Reset veriables
_stopped = False

IsInRole - VB Form Load

I've built an application out of Visual Basic with a login screen and a form. The login screen authenticates with Active Directory. After user authentication, the form loads. On form load, I would like to check to see if the authenticated user is in one of four particular Active Directory security groups. Depending on which group the authenticated user is in will depend on which buttons on the form are enabled. I've got the active directory user authentication to work for logging into the program and loading the form, but the specific code used to verifying which group the user is in does not work. Below is my code for form load.
Private Sub form_main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
button_main_pimam.Enabled = False
button_main_pimpm.Enabled = False
button_main_eim.Enabled = False
button_main_achmanager.Enabled = False
button_main_mobiliti.Enabled = False
button_main_checkfree.Enabled = False
button_main_rcm.Enabled = False
button_main_mis.Enabled = False
button_main_colson.Enabled = False
If My.User.IsInRole("domain.local\Fiserv Processing - Electronic Banking") Then
button_main_achmanager.Enabled = True
button_main_pimam.Enabled = True
button_main_pimpm.Enabled = True
button_main_eim.Enabled = True
button_main_colson.Enabled = True
button_main_colson.Enabled = True
ElseIf My.User.IsInRole("domain.local\Fiserv Processing - Operations") Then
button_main_achmanager.Enabled = True
button_main_mobiliti.Enabled = True
button_main_checkfree.Enabled = True
button_main_rcm.Enabled = True
button_main_colson.Enabled = True
ElseIf My.User.IsInRole("domain.local\Fiserv Processing - Loan Operations") Then
button_main_pimam.Enabled = True
button_main_pimpm.Enabled = True
button_main_eim.Enabled = True
button_main_achmanager.Enabled = True
button_main_mobiliti.Enabled = True
button_main_checkfree.Enabled = True
button_main_rcm.Enabled = True
button_main_mis.Enabled = True
ElseIf My.User.IsInRole("domain.local\Fiserv Processing - MIS") Then
button_main_pimam.Enabled = True
button_main_pimpm.Enabled = True
button_main_eim.Enabled = True
button_main_achmanager.Enabled = True
button_main_mobiliti.Enabled = True
button_main_checkfree.Enabled = True
button_main_rcm.Enabled = True
button_main_mis.Enabled = True
button_main_colson.Enabled = True
End If
End Sub
Regardless of which group the authenticated user is in, all the buttons are enabled for use. What am I doing wrong?
Try this approach. In your case, i would cache the array of groups that user belongs to when user authenticates, and then check whenever you need in your app.
Function IsInGroup(UserName As String, groupName As String) As Boolean
Dim vUsuario As New NTAccount(UserName)
Dim sid As SecurityIdentifier = vUsuario.Translate(GetType(SecurityIdentifier))
Using vRootDSE As New DirectoryEntry("LDAP://rootDSE")
Using vSearcher As New DirectorySearcher(New DirectoryEntry("LDAP://" + CStr(vRootDSE.Properties("defaultNamingContext")(0))), "(objectSID=" & sid.ToString() & ")", New String() {"memberOf"}, SearchScope.Subtree)
Dim src As SearchResultCollection = vSearcher.FindAll()
Dim memberOf As ResultPropertyValueCollection = src(0).Properties("memberOf")
For i As Integer = 0 To memberOf.Count - 1
'Debug.Print(memberOf(i).ToString())
' I don't really like this approach, but it's quick to write ;)
If memberOf(i).ToString().Contains("=" & groupName & ",") Then
Return True
End If
Next
End Using
End Using
Return False
End Function

What else can cause an AxWindowsMediaPlayer to play?

I have a button in my program that grabs a bunch of information from a DataGridView object (volume, url, delay, etc) and using that, it plays a file. I'm trying to get the delay to work (wait x number of seconds before playing) and I'm pretty it will work, but whenever I press the button, the play starts immediately. There is no Ctlcontrols.play() anywhere in the program except after the delay, so I have no idea what is causing it to play.
I explained my problem a little bit more in comments. Sorry if I didn't explain my code very well. If you could just tell my what else could be causing my player to start immediately, that would probably be enough.
'snd_btn_go is the button that is supposed to start it.
'This sub doesn't matter as much for the problem, it will just go to SndCueGO() if both numbers are in the valid range.
Private Sub snd_btn_go_Click(sender As Object, e As EventArgs) Handles snd_btn_go.Click
Dim cue1 As Integer
Dim cue2 As Integer
cue1 = If(Integer.TryParse(snd_txt_cue_1.Text, cue1), Int(snd_txt_cue_1.Text), snd_num1)
If snd_txt_cue_2.Text <> "" Then
cue2 = If(Integer.TryParse(snd_txt_cue_2.Text, cue2), Int(snd_txt_cue_2.Text), snd_num2)
Else
cue2 = -1
End If
If (cue1 <= dgSound.Rows.Count - 1 And cue1 > 0) Then
SndCueGO(cue1, cue2)
End If
End Sub
'This sub pulls all the info from the correct row in the DataGrid and assigns it to a list. It'll check if the start volume and end volume are the same and if they're not, it'll fade to the end volume.
Private Sub SndCueGO(cue1, cue2)
Dim cues() = {cue1, cue2}
snd_num1 = cue1
Dim cuedata1 = snd_ds.Tables(0).Rows(cue1 - 1)
Dim cuedata2 = snd_ds.Tables(0).Rows(cue1 - 1)
If cue2 <> -1 Then
snd_num2 = cue2
cuedata2 = snd_ds.Tables(0).Rows(cue2 - 1)
End If
Dim data() = {cuedata1, cuedata2}
For i = 0 To 1
If cues(i) <> -1 Then
snd_delay(i) = data(i).Item("Delay")
snd_startvol(i) = safeNum(data(i).Item("Start_Vol."))
snd_file(i) = data(i).Item("File")
snd_in(i) = data(i).Item("Fade_In")
snd_out(i) = data(i).Item("Fade_Out")
snd_vol(i) = safeNum(data(i).Item("Vol."))
snd_hold(i) = data(i).Item("Hold")
snd_af(i) = If(data(i).Item("AF") = "", False, True)
player_list(i).URL = snd_file(i)
snd_current(i) = snd_startvol(i)
If snd_startvol(i) <> snd_vol(i) Then 'snd_startvol(i) and snd_vol(i) were the same in all my tests, so this should not run.
snd_next(i) = snd_vol(i)
Dim num_steps_up = snd_in(i) * snd_speed
Dim num_steps_down = snd_out(i) * snd_speed
Dim diff = snd_vol(i) - snd_startvol(i)
Dim small_step As Single
If diff > 0 Then
small_step = diff / num_steps_up
ElseIf diff < 0 Then
small_step = diff / num_steps_down
End If
snd_steps(i) = small_step
timer_snd_fade.Tag = 0
timer_snd_fade.Enabled = True
End If
timer_snd_master.Tag = 0 'resets the tag to 0
timer_snd_master.Enabled = True 'Starts timer
End If
Next
End Sub
Private Sub timer_snd_master_Tick(sender As Object, e As EventArgs) Handles timer_snd_master.Tick
If sender.Tag = snd_delay(0) Then
Player1.Ctlcontrols.play() 'This is the only play command in the program
Debug.Print("tag " & sender.Tag) 'These print after the delay
Debug.Print("delay " & snd_delay(0))
End If
sender.Tag += 1
End Sub
Inspect the:
AxWindowsMediaPlayer player1 = ...; // get the player from UI
IWMPSettings sett = player.settings;
sett.autoStart == ??
see the docs.
Probably it is set to true, as it's default value. Simply set it to false it the player will not play until Ctlcontrols.play() is invoked.