diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index 66a7468bdb..f85ee657f6 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -3409,3 +3409,9 @@ check_github_repo <- function(owner = NULL, repo = NULL, url = NULL) { }) } } +#Convert Decimal to Fractions +frac10 <- function(x) {paste0(round(x * 10), "/", 10)} #Give fraction our of 10 for a decimal value +frac20 <- function(x) {paste0(round(x * 20), "/", 20)} #Give fraction our of 20 for a decimal value +frac100 <- function(x) {paste0(round(x * 100), "/", 100)} # Give fraction our of 100 for a decimal value + +frac_den <- function(x, den) {paste0(round(x * den), "/", den)} # Give fraction for a given denominator diff --git a/instat/ucrCalculator.Designer.vb b/instat/ucrCalculator.Designer.vb index 91563cf0e2..e2921d45d8 100644 --- a/instat/ucrCalculator.Designer.vb +++ b/instat/ucrCalculator.Designer.vb @@ -635,6 +635,10 @@ Partial Class ucrCalculator Me.ucrSelectorForCalculations = New instat.ucrSelectorByDataFrameAddRemove() Me.ucrReceiverForCalculation = New instat.ucrReceiverExpression() Me.grpFunctions = New System.Windows.Forms.GroupBox() + Me.cmdFracDen = New System.Windows.Forms.Button() + Me.cmdFrac20 = New System.Windows.Forms.Button() + Me.cmdFrac100 = New System.Windows.Forms.Button() + Me.cmdFrac10 = New System.Windows.Forms.Button() Me.cmdDigitsumSession = New System.Windows.Forms.Button() Me.cmdDigitsquSession = New System.Windows.Forms.Button() Me.cmdFunctionsDigitsum = New System.Windows.Forms.Button() @@ -7773,6 +7777,10 @@ Partial Class ucrCalculator ' 'grpFunctions ' + Me.grpFunctions.Controls.Add(Me.cmdFracDen) + Me.grpFunctions.Controls.Add(Me.cmdFrac20) + Me.grpFunctions.Controls.Add(Me.cmdFrac100) + Me.grpFunctions.Controls.Add(Me.cmdFrac10) Me.grpFunctions.Controls.Add(Me.cmdDigitsumSession) Me.grpFunctions.Controls.Add(Me.cmdDigitsquSession) Me.grpFunctions.Controls.Add(Me.cmdFunctionsDigitsum) @@ -7806,11 +7814,55 @@ Partial Class ucrCalculator Me.grpFunctions.Margin = New System.Windows.Forms.Padding(2) Me.grpFunctions.Name = "grpFunctions" Me.grpFunctions.Padding = New System.Windows.Forms.Padding(2) - Me.grpFunctions.Size = New System.Drawing.Size(259, 254) + Me.grpFunctions.Size = New System.Drawing.Size(259, 280) Me.grpFunctions.TabIndex = 216 Me.grpFunctions.TabStop = False Me.grpFunctions.Text = "Functions" ' + 'cmdFracDen + ' + Me.cmdFracDen.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.cmdFracDen.Location = New System.Drawing.Point(189, 159) + Me.cmdFracDen.Margin = New System.Windows.Forms.Padding(2) + Me.cmdFracDen.Name = "cmdFracDen" + Me.cmdFracDen.Size = New System.Drawing.Size(62, 30) + Me.cmdFracDen.TabIndex = 232 + Me.cmdFracDen.Text = "frac_den" + Me.cmdFracDen.UseVisualStyleBackColor = True + ' + 'cmdFrac20 + ' + Me.cmdFrac20.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.cmdFrac20.Location = New System.Drawing.Point(67, 159) + Me.cmdFrac20.Margin = New System.Windows.Forms.Padding(2) + Me.cmdFrac20.Name = "cmdFrac20" + Me.cmdFrac20.Size = New System.Drawing.Size(62, 30) + Me.cmdFrac20.TabIndex = 231 + Me.cmdFrac20.Text = "frac20" + Me.cmdFrac20.UseVisualStyleBackColor = True + ' + 'cmdFrac100 + ' + Me.cmdFrac100.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.cmdFrac100.Location = New System.Drawing.Point(128, 159) + Me.cmdFrac100.Margin = New System.Windows.Forms.Padding(2) + Me.cmdFrac100.Name = "cmdFrac100" + Me.cmdFrac100.Size = New System.Drawing.Size(62, 30) + Me.cmdFrac100.TabIndex = 230 + Me.cmdFrac100.Text = "frac100" + Me.cmdFrac100.UseVisualStyleBackColor = True + ' + 'cmdFrac10 + ' + Me.cmdFrac10.ImeMode = System.Windows.Forms.ImeMode.NoControl + Me.cmdFrac10.Location = New System.Drawing.Point(2, 159) + Me.cmdFrac10.Margin = New System.Windows.Forms.Padding(2) + Me.cmdFrac10.Name = "cmdFrac10" + Me.cmdFrac10.Size = New System.Drawing.Size(66, 30) + Me.cmdFrac10.TabIndex = 229 + Me.cmdFrac10.Text = "frac10" + Me.cmdFrac10.UseVisualStyleBackColor = True + ' 'cmdDigitsumSession ' Me.cmdDigitsumSession.ImeMode = System.Windows.Forms.ImeMode.NoControl @@ -7893,7 +7945,7 @@ Partial Class ucrCalculator ' Me.cmdRhelpFunctions.AutoSize = True Me.cmdRhelpFunctions.ContextMenuStrip = Me.ContextMenuStripFunctions - Me.cmdRhelpFunctions.Location = New System.Drawing.Point(165, 217) + Me.cmdRhelpFunctions.Location = New System.Drawing.Point(165, 246) Me.cmdRhelpFunctions.Margin = New System.Windows.Forms.Padding(2) Me.cmdRhelpFunctions.Name = "cmdRhelpFunctions" Me.cmdRhelpFunctions.Size = New System.Drawing.Size(86, 30) @@ -7988,7 +8040,7 @@ Partial Class ucrCalculator ' Me.cmdCoef.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!) Me.cmdCoef.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.cmdCoef.Location = New System.Drawing.Point(128, 188) + Me.cmdCoef.Location = New System.Drawing.Point(128, 217) Me.cmdCoef.Margin = New System.Windows.Forms.Padding(2) Me.cmdCoef.Name = "cmdCoef" Me.cmdCoef.Size = New System.Drawing.Size(62, 30) @@ -8012,7 +8064,7 @@ Partial Class ucrCalculator ' Me.cmdProd.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!) Me.cmdProd.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.cmdProd.Location = New System.Drawing.Point(2, 188) + Me.cmdProd.Location = New System.Drawing.Point(2, 217) Me.cmdProd.Margin = New System.Windows.Forms.Padding(2) Me.cmdProd.Name = "cmdProd" Me.cmdProd.Size = New System.Drawing.Size(66, 30) @@ -8036,7 +8088,7 @@ Partial Class ucrCalculator ' Me.cmdCombn.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!) Me.cmdCombn.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.cmdCombn.Location = New System.Drawing.Point(67, 188) + Me.cmdCombn.Location = New System.Drawing.Point(67, 217) Me.cmdCombn.Margin = New System.Windows.Forms.Padding(2) Me.cmdCombn.Name = "cmdCombn" Me.cmdCombn.Size = New System.Drawing.Size(62, 30) @@ -8060,7 +8112,7 @@ Partial Class ucrCalculator ' Me.cmdCoeffs2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!) Me.cmdCoeffs2.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.cmdCoeffs2.Location = New System.Drawing.Point(189, 188) + Me.cmdCoeffs2.Location = New System.Drawing.Point(189, 217) Me.cmdCoeffs2.Margin = New System.Windows.Forms.Padding(2) Me.cmdCoeffs2.Name = "cmdCoeffs2" Me.cmdCoeffs2.Size = New System.Drawing.Size(62, 30) @@ -8096,7 +8148,7 @@ Partial Class ucrCalculator ' Me.cmdCoeffs.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!) Me.cmdCoeffs.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.cmdCoeffs.Location = New System.Drawing.Point(189, 159) + Me.cmdCoeffs.Location = New System.Drawing.Point(189, 188) Me.cmdCoeffs.Margin = New System.Windows.Forms.Padding(2) Me.cmdCoeffs.Name = "cmdCoeffs" Me.cmdCoeffs.Size = New System.Drawing.Size(62, 30) @@ -8120,7 +8172,7 @@ Partial Class ucrCalculator ' Me.cmdRoots.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!) Me.cmdRoots.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.cmdRoots.Location = New System.Drawing.Point(128, 159) + Me.cmdRoots.Location = New System.Drawing.Point(128, 188) Me.cmdRoots.Margin = New System.Windows.Forms.Padding(2) Me.cmdRoots.Name = "cmdRoots" Me.cmdRoots.Size = New System.Drawing.Size(62, 30) @@ -8132,7 +8184,7 @@ Partial Class ucrCalculator ' Me.cmdPolynomial.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!) Me.cmdPolynomial.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.cmdPolynomial.Location = New System.Drawing.Point(2, 159) + Me.cmdPolynomial.Location = New System.Drawing.Point(2, 188) Me.cmdPolynomial.Margin = New System.Windows.Forms.Padding(2) Me.cmdPolynomial.Name = "cmdPolynomial" Me.cmdPolynomial.Size = New System.Drawing.Size(66, 30) @@ -8144,7 +8196,7 @@ Partial Class ucrCalculator ' Me.cmdOrigin.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!) Me.cmdOrigin.ImeMode = System.Windows.Forms.ImeMode.NoControl - Me.cmdOrigin.Location = New System.Drawing.Point(67, 159) + Me.cmdOrigin.Location = New System.Drawing.Point(67, 188) Me.cmdOrigin.Margin = New System.Windows.Forms.Padding(2) Me.cmdOrigin.Name = "cmdOrigin" Me.cmdOrigin.Size = New System.Drawing.Size(62, 30) @@ -8168,6 +8220,7 @@ Partial Class ucrCalculator Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0!, 96.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi Me.AutoSize = True + Me.Controls.Add(Me.grpList) Me.Controls.Add(Me.ucrChkStoreScalar) Me.Controls.Add(Me.cmdRhelpList) Me.Controls.Add(Me.cmdWakefieldHelp) @@ -8180,7 +8233,6 @@ Partial Class ucrCalculator Me.Controls.Add(Me.ucrSelectorForCalculations) Me.Controls.Add(Me.ucrReceiverForCalculation) Me.Controls.Add(Me.lblExpression) - Me.Controls.Add(Me.grpList) Me.Controls.Add(Me.grpFunctions) Me.Controls.Add(Me.grpLogical) Me.Controls.Add(Me.grpDates) @@ -8885,4 +8937,8 @@ Partial Class ucrCalculator Friend WithEvents cmdRescale As Button Friend WithEvents ScalesToolStripMenuItem As ToolStripMenuItem Friend WithEvents ucrChkStoreScalar As CheckBox + Friend WithEvents cmdFracDen As Button + Friend WithEvents cmdFrac20 As Button + Friend WithEvents cmdFrac100 As Button + Friend WithEvents cmdFrac10 As Button End Class diff --git a/instat/ucrCalculator.vb b/instat/ucrCalculator.vb index c1688b4529..745d960a3d 100644 --- a/instat/ucrCalculator.vb +++ b/instat/ucrCalculator.vb @@ -494,6 +494,10 @@ Public Class ucrCalculator ttCalculator.SetToolTip(cmdPascal, "Gives Pascal triangles, e.g. for c(1,2,3,4) gives 1, (1,1), (1, 2, 1), (1, 3, 3, 1)") ttCalculator.SetToolTip(cmdMASSFractions, "changes decimal data into a character variable with fractions. So 1.5 becomes 3/2, 0.25 becomes 1/4 etc.") ttCalculator.SetToolTip(cmdDecimals, "the inverse of the fractions key. So 3/2 becomes 1.5, 1/4 becomes 0.25 etc.") + ttCalculator.SetToolTip(cmdFrac10, "Give fraction our of 10 for a decimal value. For example for 0.36 the value is 4/10") + ttCalculator.SetToolTip(cmdFrac20, "Give fraction our of 20 for a decimal value. For example for 0.36 the value is 7/20") + ttCalculator.SetToolTip(cmdFrac100, "Give fraction our of 100 for a decimal value. For example for 0.36 the value is 36/100") + ttCalculator.SetToolTip(cmdFracDen, "Give fraction for a given denominator. For example frac_den(0.36, 50) gives 18/50") '--------------------------------------------------------------------------------------------------------------------- Const strTooltipCmdLength = "number Of observations: For example length(c(1,2,3,4,NA)) = 5 " @@ -5893,7 +5897,7 @@ Public Class ucrCalculator Private Sub cmdOrigin_Click(sender As Object, e As EventArgs) Handles cmdOrigin.Click If chkShowParameters.Checked Then - ucrReceiverForCalculation.AddToReceiverAtCursorPosition("polynom::change.origin( p= ,o= )", 6) + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("polynom::change.origin(p= ,o= )", 6) Else ucrReceiverForCalculation.AddToReceiverAtCursorPosition("polynom::change.origin(, )", 3) End If @@ -6097,4 +6101,36 @@ Public Class ucrCalculator ucrReceiverForCalculation.AddToReceiverAtCursorPosition("decimals( )", 2) End If End Sub + + Private Sub cmdFrac10_Click(sender As Object, e As EventArgs) Handles cmdFrac10.Click + If chkShowParameters.Checked Then + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("frac10(x= )", 2) + Else + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("frac10( )", 2) + End If + End Sub + + Private Sub cmdFrac20_Click(sender As Object, e As EventArgs) Handles cmdFrac20.Click + If chkShowParameters.Checked Then + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("frac20(x= )", 2) + Else + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("frac20( )", 2) + End If + End Sub + + Private Sub cmdFrac100_Click(sender As Object, e As EventArgs) Handles cmdFrac100.Click + If chkShowParameters.Checked Then + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("frac100(x= )", 2) + Else + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("frac100( )", 2) + End If + End Sub + + Private Sub cmdFracDen_Click(sender As Object, e As EventArgs) Handles cmdFracDen.Click + If chkShowParameters.Checked Then + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("frac_den(x= ,den= )", 8) + Else + ucrReceiverForCalculation.AddToReceiverAtCursorPosition("frac_den(, )", 3) + End If + End Sub End Class \ No newline at end of file